|
| 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 | +#![feature(no_core, lang_items, rustc_attrs, unsized_fn_params, transparent_unions)] |
| 5 | +#![allow(unused, improper_ctypes_definitions, internal_features)] |
| 6 | +#![no_std] |
| 7 | +#![no_core] |
| 8 | + |
| 9 | +#[lang = "sized"] |
| 10 | +pub trait Sized {} |
| 11 | + |
| 12 | +#[lang = "receiver"] |
| 13 | +pub trait Receiver {} |
| 14 | +impl<T: ?Sized> Receiver for &T {} |
| 15 | +impl<T: ?Sized> Receiver for &mut T {} |
| 16 | + |
| 17 | +#[lang = "copy"] |
| 18 | +pub trait Copy: Sized {} |
| 19 | +impl Copy for i32 {} |
| 20 | +impl Copy for f32 {} |
| 21 | +impl<T: ?Sized> Copy for &T {} |
| 22 | +impl<T: ?Sized> Copy for *const T {} |
| 23 | +impl<T: ?Sized> Copy for *mut T {} |
| 24 | + |
| 25 | +#[lang = "clone"] |
| 26 | +pub trait Clone: Sized { |
| 27 | + fn clone(&self) -> Self; |
| 28 | +} |
| 29 | + |
| 30 | +#[lang = "phantom_data"] |
| 31 | +pub struct PhantomData<T: ?Sized>; |
| 32 | +impl<T: ?Sized> Copy for PhantomData<T> {} |
| 33 | + |
| 34 | +#[lang = "unsafe_cell"] |
| 35 | +#[repr(transparent)] |
| 36 | +pub struct UnsafeCell<T: ?Sized> { |
| 37 | + value: T, |
| 38 | +} |
| 39 | + |
| 40 | +pub trait Any: 'static {} |
| 41 | + |
| 42 | +pub enum Option<T> { |
| 43 | + None, |
| 44 | + Some(T), |
| 45 | +} |
| 46 | +impl<T: Copy> Copy for Option<T> {} |
| 47 | + |
| 48 | +pub enum Result<T, E> { |
| 49 | + Ok(T), |
| 50 | + Err(E), |
| 51 | +} |
| 52 | +impl<T: Copy, E: Copy> Copy for Result<T, E> {} |
| 53 | + |
| 54 | +#[lang = "manually_drop"] |
| 55 | +#[repr(transparent)] |
| 56 | +pub struct ManuallyDrop<T: ?Sized> { |
| 57 | + value: T, |
| 58 | +} |
| 59 | +impl<T: Copy + ?Sized> Copy for ManuallyDrop<T> {} |
| 60 | + |
| 61 | +#[repr(transparent)] |
| 62 | +#[rustc_layout_scalar_valid_range_start(1)] |
| 63 | +#[rustc_nonnull_optimization_guaranteed] |
| 64 | +pub struct NonNull<T: ?Sized> { |
| 65 | + pointer: *const T, |
| 66 | +} |
| 67 | +impl<T: ?Sized> Copy for NonNull<T> {} |
| 68 | + |
| 69 | +#[repr(transparent)] |
| 70 | +#[rustc_layout_scalar_valid_range_start(1)] |
| 71 | +#[rustc_nonnull_optimization_guaranteed] |
| 72 | +pub struct NonZero<T>(T); |
| 73 | + |
| 74 | +// This just stands in for a non-trivial type. |
| 75 | +pub struct Vec<T> { |
| 76 | + ptr: NonNull<T>, |
| 77 | + cap: usize, |
| 78 | + len: usize, |
| 79 | +} |
| 80 | + |
| 81 | +pub struct Unique<T: ?Sized> { |
| 82 | + pub pointer: NonNull<T>, |
| 83 | + pub _marker: PhantomData<T>, |
| 84 | +} |
| 85 | + |
| 86 | +#[lang = "global_alloc_ty"] |
| 87 | +pub struct Global; |
| 88 | + |
| 89 | +#[lang = "owned_box"] |
| 90 | +pub struct Box<T: ?Sized, A = Global>(Unique<T>, A); |
| 91 | + |
| 92 | +#[repr(C)] |
| 93 | +struct RcBox<T: ?Sized> { |
| 94 | + strong: UnsafeCell<usize>, |
| 95 | + weak: UnsafeCell<usize>, |
| 96 | + value: T, |
| 97 | +} |
| 98 | +pub struct Rc<T: ?Sized, A = Global> { |
| 99 | + ptr: NonNull<RcBox<T>>, |
| 100 | + phantom: PhantomData<RcBox<T>>, |
| 101 | + alloc: A, |
| 102 | +} |
| 103 | + |
| 104 | +#[repr(C, align(8))] |
| 105 | +struct AtomicUsize(usize); |
| 106 | +#[repr(C)] |
| 107 | +struct ArcInner<T: ?Sized> { |
| 108 | + strong: AtomicUsize, |
| 109 | + weak: AtomicUsize, |
| 110 | + data: T, |
| 111 | +} |
| 112 | +pub struct Arc<T: ?Sized, A = Global> { |
| 113 | + ptr: NonNull<ArcInner<T>>, |
| 114 | + phantom: PhantomData<ArcInner<T>>, |
| 115 | + alloc: A, |
| 116 | +} |
0 commit comments