Skip to content

Commit 1e44566

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 1e44566

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tests/auxiliary/minicore.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
//! - Some rustc-attribute annotated items are not currently included in `minicore`. `core` items
10+
//! which has `#[rustc_layout_scalar_valid_range_start(1)]` or
11+
//! `#[rustc_nonnull_optimization_guaranteed]` are not currently included because they can easily
12+
//! UB if the user test code does not account for those requirements.
13+
//!
14+
//! # References
15+
//!
16+
//! This is partially adapted from `rustc_codegen_cranelift`:
17+
//! <https://github.com/rust-lang/rust/blob/c0b5cc9003f6464c11ae1c0662c6a7e06f6f5cab/compiler/rustc_codegen_cranelift/example/mini_core.rs>.
18+
// ignore-tidy-linelength
19+
20+
#![feature(no_core, lang_items, rustc_attrs)]
21+
#![allow(unused, improper_ctypes_definitions, internal_features)]
22+
#![no_std]
23+
#![no_core]
24+
25+
#[lang = "sized"]
26+
pub trait Sized {}
27+
28+
#[lang = "receiver"]
29+
pub trait Receiver {}
30+
impl<T: ?Sized> Receiver for &T {}
31+
impl<T: ?Sized> Receiver for &mut T {}
32+
33+
#[lang = "copy"]
34+
pub trait Copy {}
35+
36+
impl Copy for bool {}
37+
impl Copy for u8 {}
38+
impl Copy for u16 {}
39+
impl Copy for u32 {}
40+
impl Copy for u64 {}
41+
impl Copy for u128 {}
42+
impl Copy for usize {}
43+
impl Copy for i8 {}
44+
impl Copy for i16 {}
45+
impl Copy for i32 {}
46+
impl Copy for isize {}
47+
impl Copy for f32 {}
48+
impl Copy for f64 {}
49+
impl Copy for char {}
50+
impl<'a, T: ?Sized> Copy for &'a T {}
51+
impl<T: ?Sized> Copy for *const T {}
52+
impl<T: ?Sized> Copy for *mut T {}
53+
54+
#[lang = "phantom_data"]
55+
pub struct PhantomData<T: ?Sized>;
56+
impl<T: ?Sized> Copy for PhantomData<T> {}
57+
58+
pub enum Option<T> {
59+
None,
60+
Some(T),
61+
}
62+
impl<T: Copy> Copy for Option<T> {}
63+
64+
pub enum Result<T, E> {
65+
Ok(T),
66+
Err(E),
67+
}
68+
impl<T: Copy, E: Copy> Copy for Result<T, E> {}
69+
70+
#[lang = "manually_drop"]
71+
#[repr(transparent)]
72+
pub struct ManuallyDrop<T: ?Sized> {
73+
value: T,
74+
}
75+
impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {}
76+
77+
#[lang = "unsafe_cell"]
78+
#[repr(transparent)]
79+
pub struct UnsafeCell<T: ?Sized> {
80+
value: T,
81+
}
82+
83+
// Trait stub, no `type_id` method.
84+
pub trait Any: 'static {}

0 commit comments

Comments
 (0)