Skip to content

Commit 937fc66

Browse files
committed
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 150247c commit 937fc66

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/auxiliary/minicore.rs

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

0 commit comments

Comments
 (0)