Skip to content

Commit 2de1dc8

Browse files
cleaned up tests by bringing objects under mini_core into scope
1 parent fcac229 commit 2de1dc8

File tree

7 files changed

+58
-587
lines changed

7 files changed

+58
-587
lines changed

example/mini_core.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ impl Mul for usize {
139139
}
140140
}
141141

142+
impl Mul for isize {
143+
type Output = Self;
144+
145+
fn mul(self, rhs: Self) -> Self::Output {
146+
self * rhs
147+
}
148+
}
149+
142150
#[lang = "add"]
143151
pub trait Add<RHS = Self> {
144152
type Output;
@@ -162,6 +170,14 @@ impl Add for i8 {
162170
}
163171
}
164172

173+
impl Add for i32 {
174+
type Output = Self;
175+
176+
fn add(self, rhs: Self) -> Self {
177+
self + rhs
178+
}
179+
}
180+
165181
impl Add for usize {
166182
type Output = Self;
167183

@@ -193,6 +209,14 @@ impl Sub for usize {
193209
}
194210
}
195211

212+
impl Sub for isize {
213+
type Output = Self;
214+
215+
fn sub(self, rhs: Self) -> Self {
216+
self - rhs
217+
}
218+
}
219+
196220
impl Sub for u8 {
197221
type Output = Self;
198222

@@ -588,70 +612,43 @@ pub union MaybeUninit<T> {
588612

589613
pub mod intrinsics {
590614
#[rustc_intrinsic]
591-
#[rustc_intrinsic_must_be_overridden]
592-
pub fn abort() -> ! {
593-
loop {}
594-
}
615+
pub fn abort() -> !;
616+
595617
#[rustc_intrinsic]
596-
#[rustc_intrinsic_must_be_overridden]
597-
pub fn size_of<T>() -> usize {
598-
loop {}
599-
}
618+
pub fn size_of<T>() -> usize;
619+
600620
#[rustc_intrinsic]
601-
#[rustc_intrinsic_must_be_overridden]
602-
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize {
603-
loop {}
604-
}
621+
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize;
622+
605623
#[rustc_intrinsic]
606-
#[rustc_intrinsic_must_be_overridden]
607-
pub fn min_align_of<T>() -> usize {
608-
loop {}
609-
}
624+
pub fn min_align_of<T>() -> usize;
625+
610626
#[rustc_intrinsic]
611-
#[rustc_intrinsic_must_be_overridden]
612-
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize {
613-
loop {}
614-
}
627+
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize;
628+
615629
#[rustc_intrinsic]
616-
#[rustc_intrinsic_must_be_overridden]
617-
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize) {
618-
loop {}
619-
}
630+
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize);
631+
620632
#[rustc_intrinsic]
621-
#[rustc_intrinsic_must_be_overridden]
622-
pub unsafe fn transmute<T, U>(_e: T) -> U {
623-
loop {}
624-
}
633+
pub unsafe fn transmute<T, U>(_e: T) -> U;
634+
625635
#[rustc_intrinsic]
626-
#[rustc_intrinsic_must_be_overridden]
627-
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32 {
628-
loop {}
629-
}
636+
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
637+
630638
#[rustc_intrinsic]
631-
#[rustc_intrinsic_must_be_overridden]
632-
pub fn needs_drop<T: ?::Sized>() -> bool {
633-
loop {}
634-
}
639+
pub fn needs_drop<T: ?::Sized>() -> bool;
640+
635641
#[rustc_intrinsic]
636-
#[rustc_intrinsic_must_be_overridden]
637-
pub fn bitreverse<T>(_x: T) -> T {
638-
loop {}
639-
}
642+
pub fn bitreverse<T>(_x: T) -> T;
643+
640644
#[rustc_intrinsic]
641-
#[rustc_intrinsic_must_be_overridden]
642-
pub fn bswap<T>(_x: T) -> T {
643-
loop {}
644-
}
645+
pub fn bswap<T>(_x: T) -> T;
646+
645647
#[rustc_intrinsic]
646-
#[rustc_intrinsic_must_be_overridden]
647-
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize) {
648-
loop {}
649-
}
648+
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize);
649+
650650
#[rustc_intrinsic]
651-
#[rustc_intrinsic_must_be_overridden]
652-
pub unsafe fn unreachable() -> ! {
653-
loop {}
654-
}
651+
pub unsafe fn unreachable() -> !;
655652
}
656653

657654
pub mod libc {
@@ -664,6 +661,9 @@ pub mod libc {
664661
pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
665662
pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
666663
pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
664+
pub fn fflush(stream: *mut i32) -> i32;
665+
666+
pub static stdout: *mut i32;
667667
}
668668
}
669669

tests/run/abort1.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,7 @@
99
#![no_std]
1010
#![no_core]
1111

12-
/*
13-
* Core
14-
*/
15-
16-
// Because we don't have core yet.
17-
#[lang = "sized"]
18-
pub trait Sized {}
19-
20-
#[lang = "copy"]
21-
trait Copy {
22-
}
23-
24-
impl Copy for isize {}
25-
26-
#[lang = "receiver"]
27-
trait Receiver {
28-
}
29-
30-
#[lang = "freeze"]
31-
pub(crate) unsafe auto trait Freeze {}
32-
33-
mod intrinsics {
34-
use super::Sized;
35-
36-
#[rustc_nounwind]
37-
#[rustc_intrinsic]
38-
#[rustc_intrinsic_must_be_overridden]
39-
pub fn abort() -> ! {
40-
loop {}
41-
}
42-
}
12+
extern crate mini_core;
4313

4414
/*
4515
* Code

tests/run/abort2.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,7 @@
99
#![no_std]
1010
#![no_core]
1111

12-
/*
13-
* Core
14-
*/
15-
16-
// Because we don't have core yet.
17-
#[lang = "sized"]
18-
pub trait Sized {}
19-
20-
#[lang = "copy"]
21-
trait Copy {
22-
}
23-
24-
impl Copy for isize {}
25-
26-
#[lang = "receiver"]
27-
trait Receiver {
28-
}
29-
30-
#[lang = "freeze"]
31-
pub(crate) unsafe auto trait Freeze {}
32-
33-
mod intrinsics {
34-
use super::Sized;
35-
36-
#[rustc_nounwind]
37-
#[rustc_intrinsic]
38-
#[rustc_intrinsic_must_be_overridden]
39-
pub fn abort() -> ! {
40-
loop {}
41-
}
42-
}
12+
extern crate mini_core;
4313

4414
/*
4515
* Code

tests/run/assign.rs

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -11,116 +11,7 @@
1111
#![no_std]
1212
#![no_core]
1313

14-
/*
15-
* Core
16-
*/
17-
18-
// Because we don't have core yet.
19-
#[lang = "sized"]
20-
pub trait Sized {}
21-
22-
#[lang = "copy"]
23-
trait Copy {
24-
}
25-
26-
impl Copy for isize {}
27-
impl Copy for *mut i32 {}
28-
impl Copy for usize {}
29-
impl Copy for u8 {}
30-
impl Copy for i8 {}
31-
impl Copy for i32 {}
32-
33-
#[lang = "receiver"]
34-
trait Receiver {
35-
}
36-
37-
#[lang = "freeze"]
38-
pub(crate) unsafe auto trait Freeze {}
39-
40-
#[lang = "panic_location"]
41-
struct PanicLocation {
42-
file: &'static str,
43-
line: u32,
44-
column: u32,
45-
}
46-
47-
mod libc {
48-
#[link(name = "c")]
49-
extern "C" {
50-
pub fn puts(s: *const u8) -> i32;
51-
pub fn fflush(stream: *mut i32) -> i32;
52-
pub fn printf(format: *const i8, ...) -> i32;
53-
54-
pub static stdout: *mut i32;
55-
}
56-
}
57-
58-
mod intrinsics {
59-
#[rustc_nounwind]
60-
#[rustc_intrinsic]
61-
#[rustc_intrinsic_must_be_overridden]
62-
pub fn abort() -> ! {
63-
loop {}
64-
}
65-
}
66-
67-
#[lang = "panic"]
68-
#[track_caller]
69-
#[no_mangle]
70-
pub fn panic(_msg: &'static str) -> ! {
71-
unsafe {
72-
libc::puts("Panicking\0" as *const str as *const u8);
73-
libc::fflush(libc::stdout);
74-
intrinsics::abort();
75-
}
76-
}
77-
78-
#[lang = "add"]
79-
trait Add<RHS = Self> {
80-
type Output;
81-
82-
fn add(self, rhs: RHS) -> Self::Output;
83-
}
84-
85-
impl Add for u8 {
86-
type Output = Self;
87-
88-
fn add(self, rhs: Self) -> Self {
89-
self + rhs
90-
}
91-
}
92-
93-
impl Add for i8 {
94-
type Output = Self;
95-
96-
fn add(self, rhs: Self) -> Self {
97-
self + rhs
98-
}
99-
}
100-
101-
impl Add for i32 {
102-
type Output = Self;
103-
104-
fn add(self, rhs: Self) -> Self {
105-
self + rhs
106-
}
107-
}
108-
109-
impl Add for usize {
110-
type Output = Self;
111-
112-
fn add(self, rhs: Self) -> Self {
113-
self + rhs
114-
}
115-
}
116-
117-
impl Add for isize {
118-
type Output = Self;
119-
120-
fn add(self, rhs: Self) -> Self {
121-
self + rhs
122-
}
123-
}
14+
extern crate mini_core;
12415

12516
#[track_caller]
12617
#[lang = "panic_const_add_overflow"]

0 commit comments

Comments
 (0)