Skip to content

Commit 82c2e42

Browse files
committed
minicore: add minimal minicore test auxiliary
The initial `minicore` is intentionally super minimal and contains an incomplete subset of `core` items, and explicitly not items from `alloc` or `std`-only items.
1 parent 4d296ea commit 82c2e42

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tests/auxiliary/minicore.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//! Auxiliary `minicore` prelude which stubs out `core` items for `no_core` tests that need to work
2+
//! in cross-compilation scenarios where no `core` is available (that don't want nor need to
3+
//! `-Zbuild-std`).
4+
//!
5+
//! # Important notes
6+
//!
7+
//! - `minicore` is **only** intended for `core` items, and the stubs should match the actual `core`
8+
//! items.
9+
//!
10+
//! # References
11+
//!
12+
//! This is partially adapted from `rustc_codegen_cranelift`:
13+
//! <https://github.com/rust-lang/rust/blob/c0b5cc9003f6464c11ae1c0662c6a7e06f6f5cab/compiler/rustc_codegen_cranelift/example/mini_core.rs>.
14+
// ignore-tidy-linelength
15+
16+
#![feature(no_core, lang_items, rustc_attrs)]
17+
#![allow(unused, improper_ctypes_definitions, internal_features)]
18+
#![no_std]
19+
#![no_core]
20+
21+
#[lang = "sized"]
22+
pub trait Sized {}
23+
24+
#[lang = "receiver"]
25+
pub trait Receiver {}
26+
impl<T: ?Sized> Receiver for &T {}
27+
impl<T: ?Sized> Receiver for &mut T {}
28+
29+
#[lang = "copy"]
30+
pub trait Copy {}
31+
32+
impl Copy for bool {}
33+
impl Copy for u8 {}
34+
impl Copy for u16 {}
35+
impl Copy for u32 {}
36+
impl Copy for u64 {}
37+
impl Copy for u128 {}
38+
impl Copy for usize {}
39+
impl Copy for i8 {}
40+
impl Copy for i16 {}
41+
impl Copy for i32 {}
42+
impl Copy for isize {}
43+
impl Copy for f32 {}
44+
impl Copy for f64 {}
45+
impl Copy for char {}
46+
impl<'a, T: ?Sized> Copy for &'a T {}
47+
impl<T: ?Sized> Copy for *const T {}
48+
impl<T: ?Sized> Copy for *mut T {}
49+
50+
#[lang = "phantom_data"]
51+
pub struct PhantomData<T: ?Sized>;
52+
impl<T: ?Sized> Copy for PhantomData<T> {}
53+
54+
pub enum Option<T> {
55+
None,
56+
Some(T),
57+
}
58+
impl<T: Copy> Copy for Option<T> {}
59+
60+
pub enum Result<T, E> {
61+
Ok(T),
62+
Err(E),
63+
}
64+
impl<T: Copy, E: Copy> Copy for Result<T, E> {}
65+
66+
#[lang = "manually_drop"]
67+
#[repr(transparent)]
68+
pub struct ManuallyDrop<T: ?Sized> {
69+
value: T,
70+
}
71+
impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {}
72+
73+
#[lang = "unsafe_cell"]
74+
#[repr(transparent)]
75+
pub struct UnsafeCell<T: ?Sized> {
76+
value: T,
77+
}

0 commit comments

Comments
 (0)