//! This is a fixture we use for tests that need lang items. //! //! We want to include the minimal subset of core for each test, so this file //! supports "conditional compilation". Tests use the following syntax to include minicore: //! //! //- minicore: flag1, flag2 //! //! We then strip all the code marked with other flags. //! //! Available flags: //! sized: //! unsize: sized //! coerce_unsized: unsize //! slice: //! range: //! deref: sized //! deref_mut: deref //! index: sized //! fn: //! try: //! pin: //! future: pin //! option: //! result: //! iterator: option //! iterators: iterator, fn //! default: sized //! hash: //! clone: sized //! copy: clone //! from: sized //! eq: sized //! ord: eq, option //! derive: //! fmt: result //! bool_impl: option, fn //! add: //! as_ref: sized //! drop: pub mod marker { // region:sized #[lang = "sized"] #[fundamental] #[rustc_specialization_trait] pub trait Sized {} // endregion:sized // region:unsize #[lang = "unsize"] pub trait Unsize {} // endregion:unsize // region:copy #[lang = "copy"] pub trait Copy: Clone {} // region:derive #[rustc_builtin_macro] pub macro Copy($item:item) {} // endregion:derive mod copy_impls { use super::Copy; macro_rules! impl_copy { ($($t:ty)*) => { $( impl Copy for $t {} )* } } impl_copy! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 bool char } impl Copy for *const T {} impl Copy for *mut T {} impl Copy for &T {} } // endregion:copy } // region:default pub mod default { pub trait Default: Sized { fn default() -> Self; } // region:derive #[rustc_builtin_macro] pub macro Default($item:item) {} // endregion:derive } // endregion:default // region:hash pub mod hash { pub trait Hasher {} pub trait Hash { fn hash(&self, state: &mut H); } } // endregion:hash // region:clone pub mod clone { #[lang = "clone"] pub trait Clone: Sized { fn clone(&self) -> Self; } // region:derive #[rustc_builtin_macro] pub macro Clone($item:item) {} // endregion:derive } // endregion:clone pub mod convert { // region:from pub trait From: Sized { fn from(_: T) -> Self; } pub trait Into: Sized { fn into(self) -> T; } impl Into for T where U: From, { fn into(self) -> U { U::from(self) } } impl From for T { fn from(t: T) -> T { t } } // endregion:from // region:as_ref pub trait AsRef { fn as_ref(&self) -> &T; } // endregion:as_ref } pub mod ops { // region:coerce_unsized mod unsize { use crate::marker::Unsize; #[lang = "coerce_unsized"] pub trait CoerceUnsized {} impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {} impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {} impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {} impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {} impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<*const U> for &'a T {} impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} impl, U: ?Sized> CoerceUnsized<*const U> for *mut T {} impl, U: ?Sized> CoerceUnsized<*const U> for *const T {} } pub use self::unsize::CoerceUnsized; // endregion:coerce_unsized // region:deref mod deref { #[lang = "deref"] pub trait Deref { #[lang = "deref_target"] type Target: ?Sized; fn deref(&self) -> &Self::Target; } // region:deref_mut #[lang = "deref_mut"] pub trait DerefMut: Deref { fn deref_mut(&mut self) -> &mut Self::Target; } // endregion:deref_mut } pub use self::deref::{ Deref, DerefMut, // :deref_mut }; // endregion:deref // region:drop #[lang = "drop"] pub trait Drop { fn drop(&mut self); } // endregion:drop // region:index mod index { #[lang = "index"] pub trait Index { type Output: ?Sized; fn index(&self, index: Idx) -> &Self::Output; } #[lang = "index_mut"] pub trait IndexMut: Index { fn index_mut(&mut self, index: Idx) -> &mut Self::Output; } // region:slice impl Index for [T] where I: SliceIndex<[T]>, { type Output = I::Output; fn index(&self, index: I) -> &I::Output { loop {} } } impl IndexMut for [T] where I: SliceIndex<[T]>, { fn index_mut(&mut self, index: I) -> &mut I::Output { loop {} } } pub unsafe trait SliceIndex { type Output: ?Sized; } unsafe impl SliceIndex<[T]> for usize { type Output = T; } // endregion:slice } pub use self::index::{Index, IndexMut}; // endregion:index // region:drop pub mod mem { pub fn drop(_x: T) {} } // endregion:drop // region:range mod range { #[lang = "RangeFull"] pub struct RangeFull; #[lang = "Range"] pub struct Range { pub start: Idx, pub end: Idx, } #[lang = "RangeFrom"] pub struct RangeFrom { pub start: Idx, } #[lang = "RangeTo"] pub struct RangeTo { pub end: Idx, } #[lang = "RangeInclusive"] pub struct RangeInclusive { pub(crate) start: Idx, pub(crate) end: Idx, pub(crate) exhausted: bool, } #[lang = "RangeToInclusive"] pub struct RangeToInclusive { pub end: Idx, } } pub use self::range::{Range, RangeFrom, RangeFull, RangeTo}; pub use self::range::{RangeInclusive, RangeToInclusive}; // endregion:range // region:fn mod function { #[lang = "fn"] #[fundamental] pub trait Fn: FnMut {} #[lang = "fn_mut"] #[fundamental] pub trait FnMut: FnOnce {} #[lang = "fn_once"] #[fundamental] pub trait FnOnce { #[lang = "fn_once_output"] type Output; } } pub use self::function::{Fn, FnMut, FnOnce}; // endregion:fn // region:try mod try_ { pub enum ControlFlow { Continue(C), Break(B), } pub trait FromResidual { #[lang = "from_residual"] fn from_residual(residual: R) -> Self; } #[lang = "try"] pub trait Try: FromResidual { type Output; type Residual; #[lang = "from_output"] fn from_output(output: Self::Output) -> Self; #[lang = "branch"] fn branch(self) -> ControlFlow; } impl Try for ControlFlow { type Output = C; type Residual = ControlFlow; fn from_output(output: Self::Output) -> Self {} fn branch(self) -> ControlFlow {} } impl FromResidual for ControlFlow { fn from_residual(residual: ControlFlow) -> Self {} } } pub use self::try_::{ControlFlow, FromResidual, Try}; // endregion:try // region:add #[lang = "add"] pub trait Add { type Output; fn add(self, rhs: Rhs) -> Self::Output; } // endregion:add } // region:eq pub mod cmp { #[lang = "eq"] pub trait PartialEq { fn eq(&self, other: &Rhs) -> bool; fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } pub trait Eq: PartialEq {} // region:derive #[rustc_builtin_macro] pub macro PartialEq($item:item) {} #[rustc_builtin_macro] pub macro Eq($item:item) {} // endregion:derive // region:ord #[lang = "partial_ord"] pub trait PartialOrd: PartialEq { fn partial_cmp(&self, other: &Rhs) -> Option; } pub trait Ord: Eq + PartialOrd { fn cmp(&self, other: &Self) -> Ordering; } pub enum Ordering { Less = -1, Equal = 0, Greater = 1, } // region:derive #[rustc_builtin_macro] pub macro PartialOrd($item:item) {} #[rustc_builtin_macro] pub macro Ord($item:item) {} // endregion:derive // endregion:ord } // endregion:eq // region:fmt pub mod fmt { pub struct Error; pub type Result = Result<(), Error>; pub struct Formatter<'a>; pub trait Debug { fn fmt(&self, f: &mut Formatter<'_>) -> Result; } } // endregion:fmt // region:slice pub mod slice { #[lang = "slice"] impl [T] { pub fn len(&self) -> usize { loop {} } } } // endregion:slice // region:option pub mod option { pub enum Option { #[lang = "None"] None, #[lang = "Some"] Some(T), } impl Option { pub const fn unwrap(self) -> T { match self { Some(val) => val, None => panic!("called `Option::unwrap()` on a `None` value"), } } } } // endregion:option // region:result pub mod result { pub enum Result { #[lang = "Ok"] Ok(T), #[lang = "Err"] Err(E), } } // endregion:result // region:pin pub mod pin { #[lang = "pin"] #[fundamental] pub struct Pin

{ pointer: P, } } // endregion:pin // region:future pub mod future { use crate::{ pin::Pin, task::{Context, Poll}, }; #[lang = "future_trait"] pub trait Future { type Output; #[lang = "poll"] fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; } } pub mod task { pub enum Poll { #[lang = "Ready"] Ready(T), #[lang = "Pending"] Pending, } pub struct Context<'a> { waker: &'a (), } } // endregion:future // region:iterator pub mod iter { // region:iterators mod adapters { pub struct Take { iter: I, n: usize, } impl Iterator for Take where I: Iterator, { type Item = ::Item; fn next(&mut self) -> Option<::Item> { loop {} } } pub struct FilterMap { iter: I, f: F, } impl Iterator for FilterMap where F: FnMut(I::Item) -> Option, { type Item = B; #[inline] fn next(&mut self) -> Option { loop {} } } } pub use self::adapters::{Take, FilterMap}; mod sources { mod repeat { pub fn repeat(elt: T) -> Repeat { loop {} } pub struct Repeat { element: A, } impl Iterator for Repeat { type Item = A; fn next(&mut self) -> Option { loop {} } } } pub use self::repeat::{repeat, Repeat}; } pub use self::sources::{repeat, Repeat}; // endregion:iterators mod traits { mod iterator { use super::super::Take; pub trait Iterator { type Item; #[lang = "next"] fn next(&mut self) -> Option; fn nth(&mut self, n: usize) -> Option { loop {} } fn by_ref(&mut self) -> &mut Self where Self: Sized, { self } // region:iterators fn take(self, n: usize) -> crate::iter::Take { loop {} } fn filter_map(self, f: F) -> crate::iter::FilterMap where Self: Sized, F: FnMut(Self::Item) -> Option, { loop {} } // endregion:iterators } impl Iterator for &mut I { type Item = I::Item; fn next(&mut self) -> Option { (**self).next() } } } pub use self::iterator::Iterator; mod collect { pub trait IntoIterator { type Item; type IntoIter: Iterator; #[lang = "into_iter"] fn into_iter(self) -> Self::IntoIter; } impl IntoIterator for I { type Item = I::Item; type IntoIter = I; fn into_iter(self) -> I { self } } } pub use self::collect::IntoIterator; } pub use self::traits::{IntoIterator, Iterator}; } // endregion:iterator // region:derive mod macros { pub(crate) mod builtin { #[rustc_builtin_macro] pub macro derive($item:item) { /* compiler built-in */ } } } // endregion:derive // region:bool_impl #[lang = "bool"] impl bool { pub fn then T>(self, f: F) -> Option { if self { Some(f()) } else { None } } } // endregion:bool_impl pub mod prelude { pub mod v1 { pub use crate::{ clone::Clone, // :clone cmp::{Eq, PartialEq}, // :eq cmp::{Ord, PartialOrd}, // :ord convert::AsRef, // :as_ref convert::{From, Into}, // :from default::Default, // :default iter::{IntoIterator, Iterator}, // :iterator macros::builtin::derive, // :derive marker::Copy, // :copy marker::Sized, // :sized mem::drop, // :drop ops::Drop, // :drop ops::{Fn, FnMut, FnOnce}, // :fn option::Option::{self, None, Some}, // :option result::Result::{self, Err, Ok}, // :result }; } pub mod rust_2015 { pub use super::v1::*; } pub mod rust_2018 { pub use super::v1::*; } pub mod rust_2021 { pub use super::v1::*; } } #[prelude_import] #[allow(unused)] use prelude::v1::*;