]> git.lizzy.rs Git - rust.git/blob - crates/test_utils/src/minicore.rs
internal: introduce minicore -- a subset of libcore for testing
[rust.git] / crates / test_utils / src / minicore.rs
1 //! This is a fixture we use for tests that need lang items.
2 //!
3 //! We want to include the minimal subset of core for each test, so this file
4 //! supports "conditional compilation". Tests use the following syntax to include minicore:
5 //!
6 //!  //- minicore: flag1, flag2
7 //!
8 //! We then strip all the code marked with other flags.
9 //!
10 //! Available flags:
11 //!     sized:
12 //!     coerce_unsized: sized
13
14 pub mod marker {
15     // region:sized
16     #[lang = "sized"]
17     #[fundamental]
18     #[rustc_specialization_trait]
19     pub trait Sized {}
20
21     #[lang = "unsize"]
22     pub trait Unsize<T: ?Sized> {}
23     // endregion:sized
24 }
25
26 pub mod ops {
27     mod unsize {
28         // region:coerce_unsized
29         use crate::marker::Unsize;
30
31         #[lang = "coerce_unsized"]
32         pub trait CoerceUnsized<T: ?Sized> {}
33
34         impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
35         impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
36         impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
37         impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
38
39         impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
40         impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
41
42         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
43         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
44         impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
45         // endregion:coerce_unsized
46     }
47 }
48
49 pub mod prelude {
50     pub mod v1 {
51         pub use crate::marker::Sized; // :sized
52     }
53
54     pub mod rust_2015 {
55         pub use super::v1::*;
56     }
57
58     pub mod rust_2018 {
59         pub use super::v1::*;
60     }
61
62     pub mod rust_2021 {
63         pub use super::v1::*;
64     }
65 }
66
67 #[prelude_import]
68 #[allow(unused)]
69 use prelude::v1::*;