//! 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: //! add: //! asm: //! assert: //! as_ref: sized //! bool_impl: option, fn //! builtin_impls: //! cell: copy, drop //! clone: sized //! coerce_unsized: unsize //! concat: //! copy: clone //! default: sized //! deref_mut: deref //! deref: sized //! derive: //! discriminant: //! drop: //! env: option //! eq: sized //! error: fmt //! fmt: option, result, transmute, coerce_unsized //! fn: //! from: sized //! future: pin //! coroutine: pin //! hash: //! include: //! index: sized //! infallible: //! int_impl: size_of, transmute //! iterator: option //! iterators: iterator, fn //! manually_drop: drop //! non_null: //! non_zero: //! option: panic //! ord: eq, option //! panic: fmt //! phantom_data: //! pin: //! pointee: copy, send, sync, ord, hash, unpin //! range: //! result: //! send: sized //! size_of: sized //! sized: //! slice: //! sync: sized //! transmute: //! try: infallible //! unpin: sized //! unsize: sized //! todo: panic //! unimplemented: panic #![rustc_coherence_is_core] pub mod marker { // region:sized #[lang = "sized"] #[fundamental] #[rustc_specialization_trait] pub trait Sized {} // endregion:sized // region:send pub unsafe auto trait Send {} impl !Send for *const T {} impl !Send for *mut T {} // region:sync unsafe impl Send for &T {} unsafe impl Send for &mut T {} // endregion:sync // endregion:send // region:sync pub unsafe auto trait Sync {} impl !Sync for *const T {} impl !Sync for *mut T {} // endregion:sync // region:unsize #[lang = "unsize"] pub trait Unsize {} // endregion:unsize // region:unpin #[lang = "unpin"] pub auto trait Unpin {} // endregion:unpin // 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 {} impl Copy for ! {} } // endregion:copy // region:fn #[lang = "tuple_trait"] pub trait Tuple {} // endregion:fn // region:phantom_data #[lang = "phantom_data"] pub struct PhantomData; // endregion:phantom_data // region:discriminant #[lang = "discriminant_kind"] pub trait DiscriminantKind { #[lang = "discriminant_type"] type Discriminant; } // endregion:discriminant } // region:default pub mod default { pub trait Default: Sized { fn default() -> Self; } // region:derive #[rustc_builtin_macro(Default, attributes(default))] pub macro Default($item:item) {} // endregion:derive // region:builtin_impls macro_rules! impl_default { ($v:literal; $($t:ty)*) => { $( impl const Default for $t { fn default() -> Self { $v } } )* } } impl_default! { 0; usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } impl_default! { 0.0; f32 f64 } // endregion:builtin_impls } // endregion:default // region:hash pub mod hash { pub trait Hasher {} pub trait Hash { fn hash(&self, state: &mut H); } // region:derive #[rustc_builtin_macro] pub macro Hash($item:item) {} // endregion:derive } // endregion:hash // region:cell pub mod cell { use crate::mem; #[lang = "unsafe_cell"] pub struct UnsafeCell { value: T, } impl UnsafeCell { pub const fn new(value: T) -> UnsafeCell { UnsafeCell { value } } pub const fn get(&self) -> *mut T { self as *const UnsafeCell as *const T as *mut T } } pub struct Cell { value: UnsafeCell, } impl Cell { pub const fn new(value: T) -> Cell { Cell { value: UnsafeCell::new(value) } } pub fn set(&self, val: T) { let old = self.replace(val); mem::drop(old); } pub fn replace(&self, val: T) -> T { mem::replace(unsafe { &mut *self.value.get() }, val) } } impl Cell { pub fn get(&self) -> T { unsafe { *self.value.get() } } } } // endregion:cell // region:clone pub mod clone { #[lang = "clone"] pub trait Clone: Sized { fn clone(&self) -> Self; } impl Clone for &T { fn clone(&self) -> Self { *self } } // region:builtin_impls macro_rules! impl_clone { ($($t:ty)*) => { $( impl const Clone for $t { fn clone(&self) -> Self { *self } } )* } } impl_clone! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 bool char } impl Clone for ! { fn clone(&self) { *self } } // endregion:builtin_impls // 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 // region:infallible pub enum Infallible {} // endregion:infallible } pub mod mem { // region:manually_drop #[lang = "manually_drop"] #[repr(transparent)] pub struct ManuallyDrop { value: T, } impl ManuallyDrop { pub const fn new(value: T) -> ManuallyDrop { ManuallyDrop { value } } } // region:deref impl crate::ops::Deref for ManuallyDrop { type Target = T; fn deref(&self) -> &T { &self.value } } // endregion:deref // endregion:manually_drop // region:drop pub fn drop(_x: T) {} pub const fn replace(dest: &mut T, src: T) -> T { unsafe { let result = crate::ptr::read(dest); crate::ptr::write(dest, src); result } } // endregion:drop // region:transmute extern "rust-intrinsic" { pub fn transmute(src: Src) -> Dst; } // endregion:transmute // region:size_of extern "rust-intrinsic" { pub fn size_of() -> usize; } // endregion:size_of // region:discriminant use crate::marker::DiscriminantKind; pub struct Discriminant(::Discriminant); // endregion:discriminant } pub mod ptr { // region:drop #[lang = "drop_in_place"] pub unsafe fn drop_in_place(to_drop: *mut T) { unsafe { drop_in_place(to_drop) } } pub const unsafe fn read(src: *const T) -> T { *src } pub const unsafe fn write(dst: *mut T, src: T) { *dst = src; } // endregion:drop // region:pointee #[lang = "pointee_trait"] #[rustc_deny_explicit_impl(implement_via_object = false)] pub trait Pointee { #[lang = "metadata_type"] type Metadata: Copy + Send + Sync + Ord + Hash + Unpin; } // endregion:pointee // region:non_null #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] pub struct NonNull { pointer: *const T, } // region:coerce_unsized impl crate::ops::CoerceUnsized> for NonNull where T: crate::marker::Unsize { } // endregion:coerce_unsized // endregion:non_null } 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; } impl Deref for &T { type Target = T; fn deref(&self) -> &T { loop {} } } impl Deref for &mut T { type Target = T; fn deref(&self) -> &T { loop {} } } // 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 {} } } impl Index for [T; N] where I: SliceIndex<[T]>, { type Output = I::Output; fn index(&self, _index: I) -> &I::Output { loop {} } } impl IndexMut for [T; N] 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: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 { use crate::marker::Tuple; #[lang = "fn"] #[fundamental] pub trait Fn: FnMut { extern "rust-call" fn call(&self, args: Args) -> Self::Output; } #[lang = "fn_mut"] #[fundamental] pub trait FnMut: FnOnce { extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; } #[lang = "fn_once"] #[fundamental] pub trait FnOnce { #[lang = "fn_once_output"] type Output; extern "rust-call" fn call_once(self, args: Args) -> Self::Output; } mod impls { use crate::marker::Tuple; #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] impl const Fn for &F where F: ~const Fn, { extern "rust-call" fn call(&self, args: A) -> F::Output { (**self).call(args) } } #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] impl const FnMut for &F where F: ~const Fn, { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { (**self).call(args) } } #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] impl const FnOnce for &F where F: ~const Fn, { type Output = F::Output; extern "rust-call" fn call_once(self, args: A) -> F::Output { (*self).call(args) } } #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] impl const FnMut for &mut F where F: ~const FnMut, { extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output { (*self).call_mut(args) } } #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_fn_trait_ref_impls", issue = "101803")] impl const FnOnce for &mut F where F: ~const FnMut, { type Output = F::Output; extern "rust-call" fn call_once(self, args: A) -> F::Output { (*self).call_mut(args) } } } } pub use self::function::{Fn, FnMut, FnOnce}; // endregion:fn // region:try mod try_ { use super::super::convert::Infallible; pub enum ControlFlow { #[lang = "Continue"] Continue(C), #[lang = "Break"] Break(B), } pub trait FromResidual::Residual> { #[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 { ControlFlow::Continue(output) } fn branch(self) -> ControlFlow { match self { ControlFlow::Continue(x) => ControlFlow::Continue(x), ControlFlow::Break(x) => ControlFlow::Break(ControlFlow::Break(x)), } } } impl FromResidual for ControlFlow { fn from_residual(residual: ControlFlow) -> Self { match residual { ControlFlow::Break(b) => ControlFlow::Break(b), ControlFlow::Continue(_) => loop {}, } } } // region:option impl Try for Option { type Output = T; type Residual = Option; fn from_output(output: Self::Output) -> Self { Some(output) } fn branch(self) -> ControlFlow { match self { Some(x) => ControlFlow::Continue(x), None => ControlFlow::Break(None), } } } impl FromResidual for Option { fn from_residual(x: Option) -> Self { match x { None => None, Some(_) => loop {}, } } } // endregion:option // region:result // region:from use super::super::convert::From; impl Try for Result { type Output = T; type Residual = Result; fn from_output(output: Self::Output) -> Self { Ok(output) } fn branch(self) -> ControlFlow { match self { Ok(v) => ControlFlow::Continue(v), Err(e) => ControlFlow::Break(Err(e)), } } } impl> FromResidual> for Result { fn from_residual(residual: Result) -> Self { match residual { Err(e) => Err(From::from(e)), Ok(_) => loop {}, } } } // endregion:from // endregion:result } 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; } #[lang = "add_assign"] #[const_trait] pub trait AddAssign { fn add_assign(&mut self, rhs: Rhs); } // region:builtin_impls macro_rules! add_impl { ($($t:ty)*) => ($( impl const Add for $t { type Output = $t; fn add(self, other: $t) -> $t { self + other } } )*) } add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } // endregion:builtin_impls // endregion:add // region:coroutine mod coroutine { use crate::pin::Pin; #[lang = "coroutine"] pub trait Coroutine { type Yield; #[lang = "coroutine_return"] type Return; fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState; } #[lang = "coroutine_state"] pub enum CoroutineState { Yielded(Y), Complete(R), } } pub use self::coroutine::{Coroutine, CoroutineState}; // endregion:coroutine } // 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 struct DebugTuple; pub struct DebugStruct; impl Formatter<'_> { pub fn debug_tuple(&mut self, _name: &str) -> DebugTuple { DebugTuple } pub fn debug_struct(&mut self, _name: &str) -> DebugStruct { DebugStruct } } impl DebugTuple { pub fn field(&mut self, _value: &dyn Debug) -> &mut Self { self } pub fn finish(&mut self) -> Result { Ok(()) } } impl DebugStruct { pub fn field(&mut self, _name: &str, _value: &dyn Debug) -> &mut Self { self } pub fn finish(&mut self) -> Result { Ok(()) } } pub trait Debug { fn fmt(&self, f: &mut Formatter<'_>) -> Result; } pub trait Display { fn fmt(&self, f: &mut Formatter<'_>) -> Result; } mod rt { extern "C" { type Opaque; } #[lang = "format_argument"] pub struct Argument<'a> { value: &'a Opaque, formatter: fn(&Opaque, &mut Formatter<'_>) -> Result, } impl<'a> Argument<'a> { pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> Argument<'b> { use crate::mem::transmute; unsafe { Argument { formatter: transmute(f), value: transmute(x) } } } pub fn new_display<'b, T: Display>(x: &'b T) -> Argument<'_> { Self::new(x, Display::fmt) } } #[lang = "format_alignment"] pub enum Alignment { Left, Right, Center, Unknown, } #[lang = "format_count"] pub enum Count { Is(usize), Param(usize), Implied, } #[lang = "format_placeholder"] pub struct Placeholder { pub position: usize, pub fill: char, pub align: Alignment, pub flags: u32, pub precision: Count, pub width: Count, } impl Placeholder { pub const fn new( position: usize, fill: char, align: Alignment, flags: u32, precision: Count, width: Count, ) -> Self; } #[lang = "format_unsafe_arg"] pub struct UnsafeArg { _private: (), } impl UnsafeArg { pub unsafe fn new() -> Self; } } #[lang = "format_arguments"] pub struct Arguments<'a> { pieces: &'a [&'static str], fmt: Option<&'a [rt::Placeholder]>, args: &'a [rt::Argument<'a>], } impl<'a> Arguments<'a> { pub const fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> { Arguments { pieces, fmt: None, args } } pub const fn new_const(pieces: &'a [&'static str]) -> Arguments<'a> { Arguments { pieces, fmt: None, args: &[] } } pub fn new_v1_formatted( pieces: &'a [&'static str], args: &'a [rt::Argument<'a>], fmt: &'a [rt::Placeholder], _unsafe_arg: rt::UnsafeArg, ) -> Arguments<'a> { Arguments { pieces, fmt: Some(fmt), args } } } // region:derive #[rustc_builtin_macro] pub macro Debug($item:item) {} // endregion:derive // region:builtin_impls macro_rules! impl_debug { ($($t:ty)*) => { $( impl const Debug for $t { fn fmt(&self, _f: &mut Formatter<'_>) -> Result { Ok(()) } } )* } } impl_debug! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 bool char } impl Debug for [T] { fn fmt(&self, _f: &mut Formatter<'_>) -> Result { Ok(()) } } impl Debug for &T { fn fmt(&self, f: &mut Formatter<'_>) -> Result { (&**self).fmt(f) } } // endregion:builtin_impls } // endregion:fmt // region:slice pub mod slice { #[lang = "slice"] impl [T] { #[lang = "slice_len_fn"] pub fn len(&self) -> usize { loop {} } } } // endregion:slice // region:option pub mod option { pub enum Option { #[lang = "None"] None, #[lang = "Some"] Some(T), } // region:copy impl Copy for Option {} // endregion:copy impl Option { pub const fn unwrap(self) -> T { match self { Some(val) => val, None => panic!("called `Option::unwrap()` on a `None` value"), } } pub const fn as_ref(&self) -> Option<&T> { match self { Some(x) => Some(x), None => None, } } pub fn and(self, _optb: Option) -> Option { loop {} } pub fn unwrap_or(self, default: T) -> T { match self { Some(val) => val, None => default, } } // region:result pub const fn ok_or(self, err: E) -> Result { match self { Some(v) => Ok(v), None => Err(err), } } // endregion:result // region:fn pub fn and_then(self, _f: F) -> Option where F: FnOnce(T) -> Option, { loop {} } pub fn unwrap_or_else(self, _f: F) -> T where F: FnOnce() -> T, { loop {} } pub fn map_or(self, _default: U, _f: F) -> U where F: FnOnce(T) -> U, { loop {} } pub fn map_or_else(self, _default: D, _f: F) -> U where D: FnOnce() -> U, F: FnOnce(T) -> U, { loop {} } // endregion:fn } } // 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, } impl

Pin

{ pub fn new(_pointer: P) -> Pin

{ loop {} } } // region:deref impl crate::ops::Deref for Pin

{ type Target = P::Target; fn deref(&self) -> &P::Target { loop {} } } // endregion:deref } // endregion:pin // region:future pub mod future { use crate::{ pin::Pin, task::{Context, Poll}, }; #[doc(notable_trait)] #[lang = "future_trait"] pub trait Future { type Output; #[lang = "poll"] fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll; } pub trait IntoFuture { type Output; type IntoFuture: Future; #[lang = "into_future"] fn into_future(self) -> Self::IntoFuture; } impl IntoFuture for F { type Output = F::Output; type IntoFuture = F; fn into_future(self) -> F { self } } } 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::{FilterMap, Take}; 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 { #[doc(notable_trait)] 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 } } struct IndexRange { start: usize, end: usize, } pub struct IntoIter { data: [T; N], range: IndexRange, } impl IntoIterator for [T; N] { type Item = T; type IntoIter = IntoIter; fn into_iter(self) -> I { IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } } } } impl Iterator for IntoIter { type Item = T; fn next(&mut self) -> Option { loop {} } } } pub use self::collect::IntoIterator; } pub use self::traits::{IntoIterator, Iterator}; } // endregion:iterator // region:panic mod panic { pub macro panic_2021 { () => ( $crate::panicking::panic("explicit panic") ), ($($t:tt)+) => ( $crate::panicking::panic_fmt($crate::const_format_args!($($t)+)) ), } } mod panicking { #[lang = "panic_fmt"] pub const fn panic_fmt(_fmt: crate::fmt::Arguments<'_>) -> ! { loop {} } #[lang = "panic"] pub const fn panic(expr: &'static str) -> ! { panic_fmt(crate::fmt::Arguments::new_const(&[expr])) } } // endregion:panic mod macros { // region:panic #[macro_export] #[rustc_builtin_macro(core_panic)] macro_rules! panic { ($($arg:tt)*) => { /* compiler built-in */ }; } // endregion:panic // region:asm #[macro_export] #[rustc_builtin_macro] macro_rules! asm { ($($arg:tt)*) => { /* compiler built-in */ }; } // endregion:asm // region:assert #[macro_export] #[rustc_builtin_macro] #[allow_internal_unstable(core_panic, edition_panic, generic_assert_internals)] macro_rules! assert { ($($arg:tt)*) => { /* compiler built-in */ }; } // endregion:assert // region:fmt #[allow_internal_unstable(fmt_internals, const_fmt_arguments_new)] #[macro_export] #[rustc_builtin_macro] macro_rules! const_format_args { ($fmt:expr) => {{ /* compiler built-in */ }}; ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }}; } #[allow_internal_unstable(fmt_internals)] #[macro_export] #[rustc_builtin_macro] macro_rules! format_args { ($fmt:expr) => {{ /* compiler built-in */ }}; ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }}; } #[allow_internal_unstable(fmt_internals)] #[macro_export] #[rustc_builtin_macro] macro_rules! format_args_nl { ($fmt:expr) => {{ /* compiler built-in */ }}; ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }}; } #[macro_export] macro_rules! print { ($($arg:tt)*) => {{ $crate::io::_print($crate::format_args!($($arg)*)); }}; } // endregion:fmt // region:todo #[macro_export] #[allow_internal_unstable(core_panic)] macro_rules! todo { () => { $crate::panicking::panic("not yet implemented") }; ($($arg:tt)+) => { $crate::panic!("not yet implemented: {}", $crate::format_args!($($arg)+)) }; } // endregion:todo // region:unimplemented #[macro_export] #[allow_internal_unstable(core_panic)] macro_rules! unimplemented { () => { $crate::panicking::panic("not implemented") }; ($($arg:tt)+) => { $crate::panic!("not implemented: {}", $crate::format_args!($($arg)+)) }; } // endregion:unimplemented // region:derive pub(crate) mod builtin { #[rustc_builtin_macro] pub macro derive($item:item) { /* compiler built-in */ } #[rustc_builtin_macro] pub macro derive_const($item:item) { /* compiler built-in */ } } // endregion:derive // region:include #[rustc_builtin_macro] #[macro_export] macro_rules! include { ($file:expr $(,)?) => {{ /* compiler built-in */ }}; } // endregion:include // region:concat #[rustc_builtin_macro] #[macro_export] macro_rules! concat {} // endregion:concat // region:env #[rustc_builtin_macro] #[macro_export] macro_rules! env {} #[rustc_builtin_macro] #[macro_export] macro_rules! option_env {} // endregion:env } // region:non_zero pub mod num { #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] pub struct NonZeroU8(u8); } // endregion:non_zero // region:bool_impl #[lang = "bool"] impl bool { pub fn then T>(self, f: F) -> Option { if self { Some(f()) } else { None } } } // endregion:bool_impl // region:int_impl macro_rules! impl_int { ($($t:ty)*) => { $( impl $t { pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { unsafe { mem::transmute(bytes) } } } )* } } impl_int! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } // endregion:int_impl // region:error pub mod error { #[rustc_has_incoherent_inherent_impls] pub trait Error: crate::fmt::Debug + crate::fmt::Display { fn source(&self) -> Option<&(dyn Error + 'static)> { None } } } // endregion:error 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_const}, // :derive marker::Copy, // :copy marker::Send, // :send marker::Sized, // :sized marker::Sync, // :sync mem::drop, // :drop ops::Drop, // :drop ops::{Fn, FnMut, FnOnce}, // :fn option::Option::{self, None, Some}, // :option panic, // :panic 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::*;