2021-06-15 13:02:40 -05:00
|
|
|
//! 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:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! add:
|
2023-12-05 09:30:57 -06:00
|
|
|
//! asm:
|
|
|
|
//! assert:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! as_ref: sized
|
|
|
|
//! bool_impl: option, fn
|
2023-05-03 05:44:47 -05:00
|
|
|
//! builtin_impls:
|
2023-04-28 12:14:30 -05:00
|
|
|
//! cell: copy, drop
|
2022-10-06 07:31:06 -05:00
|
|
|
//! clone: sized
|
2021-06-16 02:48:07 -05:00
|
|
|
//! coerce_unsized: unsize
|
2023-12-02 09:50:21 -06:00
|
|
|
//! concat:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! copy: clone
|
|
|
|
//! default: sized
|
2021-06-16 02:30:29 -05:00
|
|
|
//! deref_mut: deref
|
2022-10-06 07:31:06 -05:00
|
|
|
//! deref: sized
|
|
|
|
//! derive:
|
2023-06-23 12:38:05 -05:00
|
|
|
//! discriminant:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! drop:
|
2024-01-08 03:37:09 -06:00
|
|
|
//! env: option
|
2022-10-06 07:31:06 -05:00
|
|
|
//! eq: sized
|
2022-12-04 13:12:11 -06:00
|
|
|
//! error: fmt
|
2024-01-30 02:51:28 -06:00
|
|
|
//! fmt: option, result, transmute, coerce_unsized
|
2021-06-16 02:48:07 -05:00
|
|
|
//! fn:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! from: sized
|
2021-06-15 14:49:00 -05:00
|
|
|
//! future: pin
|
2023-12-25 16:12:45 -06:00
|
|
|
//! coroutine: pin
|
2022-10-06 07:31:06 -05:00
|
|
|
//! hash:
|
2023-06-04 03:02:11 -05:00
|
|
|
//! include:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! index: sized
|
2023-01-21 11:47:37 -06:00
|
|
|
//! infallible:
|
2023-06-05 06:27:19 -05:00
|
|
|
//! int_impl: size_of, transmute
|
2021-06-16 14:48:48 -05:00
|
|
|
//! iterator: option
|
2021-06-18 15:48:18 -05:00
|
|
|
//! iterators: iterator, fn
|
2023-04-23 13:25:47 -05:00
|
|
|
//! manually_drop: drop
|
2023-06-25 17:27:12 -05:00
|
|
|
//! non_null:
|
2022-10-27 14:58:34 -05:00
|
|
|
//! non_zero:
|
2023-04-18 09:08:38 -05:00
|
|
|
//! option: panic
|
2021-06-17 16:30:22 -05:00
|
|
|
//! ord: eq, option
|
2023-05-18 10:00:49 -05:00
|
|
|
//! panic: fmt
|
2023-05-26 09:41:45 -05:00
|
|
|
//! phantom_data:
|
2022-10-06 07:31:06 -05:00
|
|
|
//! pin:
|
2023-11-14 03:08:19 -06:00
|
|
|
//! pointee: copy, send, sync, ord, hash, unpin
|
2022-10-06 07:31:06 -05:00
|
|
|
//! range:
|
|
|
|
//! result:
|
2022-12-04 13:12:11 -06:00
|
|
|
//! send: sized
|
2023-06-05 06:27:19 -05:00
|
|
|
//! size_of: sized
|
2022-10-06 07:31:06 -05:00
|
|
|
//! sized:
|
|
|
|
//! slice:
|
2022-12-04 13:12:11 -06:00
|
|
|
//! sync: sized
|
2023-05-18 10:00:49 -05:00
|
|
|
//! transmute:
|
2023-01-21 11:47:37 -06:00
|
|
|
//! try: infallible
|
2023-11-14 03:08:19 -06:00
|
|
|
//! unpin: sized
|
2022-10-06 07:31:06 -05:00
|
|
|
//! unsize: sized
|
2024-02-01 03:02:19 -06:00
|
|
|
//! todo: panic
|
|
|
|
//! unimplemented: panic
|
2021-06-15 13:02:40 -05:00
|
|
|
|
2023-01-20 16:09:35 -06:00
|
|
|
#![rustc_coherence_is_core]
|
|
|
|
|
2021-06-15 13:02:40 -05:00
|
|
|
pub mod marker {
|
|
|
|
// region:sized
|
|
|
|
#[lang = "sized"]
|
|
|
|
#[fundamental]
|
|
|
|
#[rustc_specialization_trait]
|
|
|
|
pub trait Sized {}
|
2021-06-15 13:11:53 -05:00
|
|
|
// endregion:sized
|
2021-06-15 13:02:40 -05:00
|
|
|
|
2022-12-04 13:12:11 -06:00
|
|
|
// region:send
|
|
|
|
pub unsafe auto trait Send {}
|
|
|
|
|
|
|
|
impl<T: ?Sized> !Send for *const T {}
|
|
|
|
impl<T: ?Sized> !Send for *mut T {}
|
|
|
|
// region:sync
|
|
|
|
unsafe impl<T: Sync + ?Sized> Send for &T {}
|
|
|
|
unsafe impl<T: Send + ?Sized> Send for &mut T {}
|
|
|
|
// endregion:sync
|
|
|
|
// endregion:send
|
|
|
|
|
|
|
|
// region:sync
|
|
|
|
pub unsafe auto trait Sync {}
|
|
|
|
|
|
|
|
impl<T: ?Sized> !Sync for *const T {}
|
|
|
|
impl<T: ?Sized> !Sync for *mut T {}
|
|
|
|
// endregion:sync
|
|
|
|
|
2021-06-15 13:11:53 -05:00
|
|
|
// region:unsize
|
2021-06-15 13:02:40 -05:00
|
|
|
#[lang = "unsize"]
|
|
|
|
pub trait Unsize<T: ?Sized> {}
|
2021-06-15 13:11:53 -05:00
|
|
|
// endregion:unsize
|
2021-06-18 14:10:29 -05:00
|
|
|
|
2023-11-14 03:08:19 -06:00
|
|
|
// region:unpin
|
|
|
|
#[lang = "unpin"]
|
|
|
|
pub auto trait Unpin {}
|
|
|
|
// endregion:unpin
|
|
|
|
|
2021-06-18 14:10:29 -05:00
|
|
|
// 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<T: ?Sized> Copy for *const T {}
|
|
|
|
impl<T: ?Sized> Copy for *mut T {}
|
|
|
|
impl<T: ?Sized> Copy for &T {}
|
2023-05-18 10:47:06 -05:00
|
|
|
impl Copy for ! {}
|
2021-06-18 14:10:29 -05:00
|
|
|
}
|
|
|
|
// endregion:copy
|
2023-01-27 04:06:41 -06:00
|
|
|
|
|
|
|
// region:fn
|
|
|
|
#[lang = "tuple_trait"]
|
|
|
|
pub trait Tuple {}
|
|
|
|
// endregion:fn
|
2023-05-26 09:41:45 -05:00
|
|
|
|
|
|
|
// region:phantom_data
|
|
|
|
#[lang = "phantom_data"]
|
|
|
|
pub struct PhantomData<T: ?Sized>;
|
|
|
|
// endregion:phantom_data
|
2023-06-23 12:38:05 -05:00
|
|
|
|
|
|
|
// region:discriminant
|
|
|
|
#[lang = "discriminant_kind"]
|
|
|
|
pub trait DiscriminantKind {
|
|
|
|
#[lang = "discriminant_type"]
|
|
|
|
type Discriminant;
|
|
|
|
}
|
|
|
|
// endregion:discriminant
|
2021-06-15 13:02:40 -05:00
|
|
|
}
|
|
|
|
|
2021-06-17 12:49:49 -05:00
|
|
|
// region:default
|
|
|
|
pub mod default {
|
|
|
|
pub trait Default: Sized {
|
|
|
|
fn default() -> Self;
|
|
|
|
}
|
2021-10-19 06:50:08 -05:00
|
|
|
// region:derive
|
2022-11-07 06:24:17 -06:00
|
|
|
#[rustc_builtin_macro(Default, attributes(default))]
|
2021-10-19 06:50:08 -05:00
|
|
|
pub macro Default($item:item) {}
|
|
|
|
// endregion:derive
|
2023-05-03 05:44:47 -05:00
|
|
|
|
|
|
|
// 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
|
2021-06-17 12:49:49 -05:00
|
|
|
}
|
|
|
|
// endregion:default
|
|
|
|
|
2021-08-10 04:59:41 -05:00
|
|
|
// region:hash
|
|
|
|
pub mod hash {
|
|
|
|
pub trait Hasher {}
|
|
|
|
|
|
|
|
pub trait Hash {
|
|
|
|
fn hash<H: Hasher>(&self, state: &mut H);
|
|
|
|
}
|
2023-05-03 05:44:47 -05:00
|
|
|
|
|
|
|
// region:derive
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
pub macro Hash($item:item) {}
|
|
|
|
// endregion:derive
|
2021-08-10 04:59:41 -05:00
|
|
|
}
|
|
|
|
// endregion:hash
|
|
|
|
|
2023-04-28 12:14:30 -05:00
|
|
|
// region:cell
|
|
|
|
pub mod cell {
|
|
|
|
use crate::mem;
|
|
|
|
|
|
|
|
#[lang = "unsafe_cell"]
|
|
|
|
pub struct UnsafeCell<T: ?Sized> {
|
|
|
|
value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> UnsafeCell<T> {
|
|
|
|
pub const fn new(value: T) -> UnsafeCell<T> {
|
|
|
|
UnsafeCell { value }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const fn get(&self) -> *mut T {
|
|
|
|
self as *const UnsafeCell<T> as *const T as *mut T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Cell<T: ?Sized> {
|
|
|
|
value: UnsafeCell<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Cell<T> {
|
|
|
|
pub const fn new(value: T) -> Cell<T> {
|
|
|
|
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<T: Copy> Cell<T> {
|
|
|
|
pub fn get(&self) -> T {
|
|
|
|
unsafe { *self.value.get() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:cell
|
|
|
|
|
2021-06-18 14:10:29 -05:00
|
|
|
// region:clone
|
|
|
|
pub mod clone {
|
|
|
|
#[lang = "clone"]
|
|
|
|
pub trait Clone: Sized {
|
|
|
|
fn clone(&self) -> Self;
|
|
|
|
}
|
2023-04-07 11:03:14 -05:00
|
|
|
|
|
|
|
impl<T> Clone for &T {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 05:44:47 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2023-05-18 10:47:06 -05:00
|
|
|
|
|
|
|
impl Clone for ! {
|
|
|
|
fn clone(&self) {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 05:44:47 -05:00
|
|
|
// endregion:builtin_impls
|
|
|
|
|
2021-06-18 14:10:29 -05:00
|
|
|
// region:derive
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
pub macro Clone($item:item) {}
|
|
|
|
// endregion:derive
|
|
|
|
}
|
|
|
|
// endregion:clone
|
|
|
|
|
2021-06-17 12:58:05 -05:00
|
|
|
pub mod convert {
|
2021-09-29 07:04:32 -05:00
|
|
|
// region:from
|
2021-06-17 12:58:05 -05:00
|
|
|
pub trait From<T>: Sized {
|
|
|
|
fn from(_: T) -> Self;
|
|
|
|
}
|
|
|
|
pub trait Into<T>: Sized {
|
|
|
|
fn into(self) -> T;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U> Into<U> for T
|
|
|
|
where
|
|
|
|
U: From<T>,
|
|
|
|
{
|
|
|
|
fn into(self) -> U {
|
|
|
|
U::from(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<T> for T {
|
|
|
|
fn from(t: T) -> T {
|
|
|
|
t
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 07:04:32 -05:00
|
|
|
// endregion:from
|
|
|
|
|
|
|
|
// region:as_ref
|
|
|
|
pub trait AsRef<T: ?Sized> {
|
|
|
|
fn as_ref(&self) -> &T;
|
|
|
|
}
|
|
|
|
// endregion:as_ref
|
2023-01-21 11:47:37 -06:00
|
|
|
// region:infallible
|
2023-03-08 11:28:52 -06:00
|
|
|
pub enum Infallible {}
|
2023-01-21 11:47:37 -06:00
|
|
|
// endregion:infallible
|
2021-06-17 12:58:05 -05:00
|
|
|
}
|
|
|
|
|
2023-04-18 09:08:38 -05:00
|
|
|
pub mod mem {
|
2023-04-23 13:25:47 -05:00
|
|
|
// region:manually_drop
|
|
|
|
#[lang = "manually_drop"]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct ManuallyDrop<T: ?Sized> {
|
|
|
|
value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> ManuallyDrop<T> {
|
|
|
|
pub const fn new(value: T) -> ManuallyDrop<T> {
|
|
|
|
ManuallyDrop { value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// region:deref
|
|
|
|
impl<T: ?Sized> crate::ops::Deref for ManuallyDrop<T> {
|
|
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
&self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:deref
|
|
|
|
|
|
|
|
// endregion:manually_drop
|
|
|
|
|
2024-01-30 14:04:37 -06:00
|
|
|
// region:drop
|
2023-04-18 09:08:38 -05:00
|
|
|
pub fn drop<T>(_x: T) {}
|
2023-04-28 12:14:30 -05:00
|
|
|
pub const fn replace<T>(dest: &mut T, src: T) -> T {
|
|
|
|
unsafe {
|
2023-05-18 10:47:06 -05:00
|
|
|
let result = crate::ptr::read(dest);
|
|
|
|
crate::ptr::write(dest, src);
|
2023-04-28 12:14:30 -05:00
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
2023-05-18 10:00:49 -05:00
|
|
|
// endregion:drop
|
|
|
|
|
|
|
|
// region:transmute
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
pub fn transmute<Src, Dst>(src: Src) -> Dst;
|
|
|
|
}
|
|
|
|
// endregion:transmute
|
2023-06-05 06:27:19 -05:00
|
|
|
|
|
|
|
// region:size_of
|
|
|
|
extern "rust-intrinsic" {
|
|
|
|
pub fn size_of<T>() -> usize;
|
|
|
|
}
|
|
|
|
// endregion:size_of
|
2023-07-14 11:45:18 -05:00
|
|
|
|
|
|
|
// region:discriminant
|
|
|
|
use crate::marker::DiscriminantKind;
|
|
|
|
pub struct Discriminant<T>(<T as DiscriminantKind>::Discriminant);
|
|
|
|
// endregion:discriminant
|
2023-04-18 09:08:38 -05:00
|
|
|
}
|
2023-05-12 09:47:15 -05:00
|
|
|
|
|
|
|
pub mod ptr {
|
2023-05-18 10:00:49 -05:00
|
|
|
// region:drop
|
2023-05-12 09:47:15 -05:00
|
|
|
#[lang = "drop_in_place"]
|
|
|
|
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|
|
|
unsafe { drop_in_place(to_drop) }
|
|
|
|
}
|
2023-05-18 10:47:06 -05:00
|
|
|
pub const unsafe fn read<T>(src: *const T) -> T {
|
|
|
|
*src
|
|
|
|
}
|
|
|
|
pub const unsafe fn write<T>(dst: *mut T, src: T) {
|
|
|
|
*dst = src;
|
|
|
|
}
|
2023-05-18 10:00:49 -05:00
|
|
|
// endregion:drop
|
2023-04-30 15:34:11 -05:00
|
|
|
|
|
|
|
// region:pointee
|
|
|
|
#[lang = "pointee_trait"]
|
2023-11-14 03:08:19 -06:00
|
|
|
#[rustc_deny_explicit_impl(implement_via_object = false)]
|
2023-04-30 15:34:11 -05:00
|
|
|
pub trait Pointee {
|
|
|
|
#[lang = "metadata_type"]
|
2023-11-14 03:08:19 -06:00
|
|
|
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
|
2023-04-30 15:34:11 -05:00
|
|
|
}
|
|
|
|
// endregion:pointee
|
2023-06-25 17:27:12 -05:00
|
|
|
// region:non_null
|
|
|
|
#[rustc_layout_scalar_valid_range_start(1)]
|
|
|
|
#[rustc_nonnull_optimization_guaranteed]
|
|
|
|
pub struct NonNull<T: ?Sized> {
|
|
|
|
pointer: *const T,
|
|
|
|
}
|
|
|
|
// region:coerce_unsized
|
|
|
|
impl<T: ?Sized, U: ?Sized> crate::ops::CoerceUnsized<NonNull<U>> for NonNull<T> where
|
|
|
|
T: crate::marker::Unsize<U>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// endregion:coerce_unsized
|
|
|
|
// endregion:non_null
|
2023-05-12 09:47:15 -05:00
|
|
|
}
|
2023-04-18 09:08:38 -05:00
|
|
|
|
2021-06-15 13:02:40 -05:00
|
|
|
pub mod ops {
|
2021-06-15 13:34:26 -05:00
|
|
|
// region:coerce_unsized
|
2021-06-15 13:02:40 -05:00
|
|
|
mod unsize {
|
|
|
|
use crate::marker::Unsize;
|
|
|
|
|
|
|
|
#[lang = "coerce_unsized"]
|
|
|
|
pub trait CoerceUnsized<T: ?Sized> {}
|
|
|
|
|
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
|
|
|
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
|
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
|
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
|
|
|
|
|
|
|
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
|
|
|
|
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
|
|
|
}
|
2021-06-15 13:34:26 -05:00
|
|
|
pub use self::unsize::CoerceUnsized;
|
|
|
|
// endregion:coerce_unsized
|
2021-06-15 13:11:53 -05:00
|
|
|
|
2021-06-15 13:34:26 -05:00
|
|
|
// region:deref
|
|
|
|
mod deref {
|
|
|
|
#[lang = "deref"]
|
|
|
|
pub trait Deref {
|
|
|
|
#[lang = "deref_target"]
|
|
|
|
type Target: ?Sized;
|
|
|
|
fn deref(&self) -> &Self::Target;
|
|
|
|
}
|
2022-09-09 01:27:25 -05:00
|
|
|
|
|
|
|
impl<T: ?Sized> Deref for &T {
|
|
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<T: ?Sized> Deref for &mut T {
|
|
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &T {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 02:30:29 -05:00
|
|
|
// region:deref_mut
|
|
|
|
#[lang = "deref_mut"]
|
|
|
|
pub trait DerefMut: Deref {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target;
|
|
|
|
}
|
|
|
|
// endregion:deref_mut
|
2021-06-15 13:34:26 -05:00
|
|
|
}
|
2021-06-18 14:10:29 -05:00
|
|
|
pub use self::deref::{
|
|
|
|
Deref,
|
|
|
|
DerefMut, // :deref_mut
|
|
|
|
};
|
|
|
|
// endregion:deref
|
2021-06-15 13:45:25 -05:00
|
|
|
|
2021-12-21 19:25:38 -06:00
|
|
|
// region:drop
|
|
|
|
#[lang = "drop"]
|
|
|
|
pub trait Drop {
|
|
|
|
fn drop(&mut self);
|
|
|
|
}
|
|
|
|
// endregion:drop
|
|
|
|
|
2021-06-18 14:37:03 -05:00
|
|
|
// region:index
|
|
|
|
mod index {
|
|
|
|
#[lang = "index"]
|
|
|
|
pub trait Index<Idx: ?Sized> {
|
|
|
|
type Output: ?Sized;
|
|
|
|
fn index(&self, index: Idx) -> &Self::Output;
|
|
|
|
}
|
|
|
|
#[lang = "index_mut"]
|
|
|
|
pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
|
|
|
|
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
// region:slice
|
|
|
|
impl<T, I> Index<I> for [T]
|
|
|
|
where
|
|
|
|
I: SliceIndex<[T]>,
|
|
|
|
{
|
|
|
|
type Output = I::Output;
|
2023-09-24 15:15:36 -05:00
|
|
|
fn index(&self, _index: I) -> &I::Output {
|
2021-06-18 14:37:03 -05:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<T, I> IndexMut<I> for [T]
|
|
|
|
where
|
|
|
|
I: SliceIndex<[T]>,
|
|
|
|
{
|
2023-09-24 15:15:36 -05:00
|
|
|
fn index_mut(&mut self, _index: I) -> &mut I::Output {
|
2021-06-18 14:37:03 -05:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 10:53:38 -06:00
|
|
|
impl<T, I, const N: usize> Index<I> for [T; N]
|
|
|
|
where
|
|
|
|
I: SliceIndex<[T]>,
|
|
|
|
{
|
|
|
|
type Output = I::Output;
|
2023-09-24 15:15:36 -05:00
|
|
|
fn index(&self, _index: I) -> &I::Output {
|
2023-01-31 10:53:38 -06:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<T, I, const N: usize> IndexMut<I> for [T; N]
|
|
|
|
where
|
|
|
|
I: SliceIndex<[T]>,
|
|
|
|
{
|
2023-09-24 15:15:36 -05:00
|
|
|
fn index_mut(&mut self, _index: I) -> &mut I::Output {
|
2023-01-31 10:53:38 -06:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 14:37:03 -05:00
|
|
|
pub unsafe trait SliceIndex<T: ?Sized> {
|
|
|
|
type Output: ?Sized;
|
|
|
|
}
|
|
|
|
unsafe impl<T> SliceIndex<[T]> for usize {
|
|
|
|
type Output = T;
|
|
|
|
}
|
|
|
|
// endregion:slice
|
|
|
|
}
|
|
|
|
pub use self::index::{Index, IndexMut};
|
|
|
|
// endregion:index
|
|
|
|
|
2021-06-15 14:38:21 -05:00
|
|
|
// region:range
|
2021-06-15 13:45:25 -05:00
|
|
|
mod range {
|
|
|
|
#[lang = "RangeFull"]
|
|
|
|
pub struct RangeFull;
|
|
|
|
|
|
|
|
#[lang = "Range"]
|
|
|
|
pub struct Range<Idx> {
|
|
|
|
pub start: Idx,
|
|
|
|
pub end: Idx,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "RangeFrom"]
|
|
|
|
pub struct RangeFrom<Idx> {
|
|
|
|
pub start: Idx,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "RangeTo"]
|
|
|
|
pub struct RangeTo<Idx> {
|
|
|
|
pub end: Idx,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "RangeInclusive"]
|
|
|
|
pub struct RangeInclusive<Idx> {
|
|
|
|
pub(crate) start: Idx,
|
|
|
|
pub(crate) end: Idx,
|
|
|
|
pub(crate) exhausted: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "RangeToInclusive"]
|
|
|
|
pub struct RangeToInclusive<Idx> {
|
|
|
|
pub end: Idx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
|
|
|
|
pub use self::range::{RangeInclusive, RangeToInclusive};
|
2021-06-15 14:38:21 -05:00
|
|
|
// endregion:range
|
2021-06-16 02:48:07 -05:00
|
|
|
|
|
|
|
// region:fn
|
|
|
|
mod function {
|
2023-01-27 04:06:41 -06:00
|
|
|
use crate::marker::Tuple;
|
|
|
|
|
2021-06-16 02:48:07 -05:00
|
|
|
#[lang = "fn"]
|
|
|
|
#[fundamental]
|
2023-01-27 04:06:41 -06:00
|
|
|
pub trait Fn<Args: Tuple>: FnMut<Args> {
|
|
|
|
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
|
|
|
|
}
|
2021-06-16 02:48:07 -05:00
|
|
|
|
|
|
|
#[lang = "fn_mut"]
|
|
|
|
#[fundamental]
|
2023-01-27 04:06:41 -06:00
|
|
|
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
|
|
|
}
|
2021-06-16 02:48:07 -05:00
|
|
|
|
|
|
|
#[lang = "fn_once"]
|
|
|
|
#[fundamental]
|
2023-01-27 04:06:41 -06:00
|
|
|
pub trait FnOnce<Args: Tuple> {
|
2021-06-16 02:48:07 -05:00
|
|
|
#[lang = "fn_once_output"]
|
|
|
|
type Output;
|
2023-01-27 04:06:41 -06:00
|
|
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
2021-06-16 02:48:07 -05:00
|
|
|
}
|
2023-03-17 05:32:55 -05:00
|
|
|
|
|
|
|
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<A: Tuple, F: ?Sized> const Fn<A> for &F
|
|
|
|
where
|
|
|
|
F: ~const Fn<A>,
|
|
|
|
{
|
|
|
|
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<A: Tuple, F: ?Sized> const FnMut<A> for &F
|
|
|
|
where
|
|
|
|
F: ~const Fn<A>,
|
|
|
|
{
|
|
|
|
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<A: Tuple, F: ?Sized> const FnOnce<A> for &F
|
|
|
|
where
|
|
|
|
F: ~const Fn<A>,
|
|
|
|
{
|
|
|
|
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<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
|
|
|
|
where
|
|
|
|
F: ~const FnMut<A>,
|
|
|
|
{
|
|
|
|
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<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
|
|
|
|
where
|
|
|
|
F: ~const FnMut<A>,
|
|
|
|
{
|
|
|
|
type Output = F::Output;
|
|
|
|
extern "rust-call" fn call_once(self, args: A) -> F::Output {
|
|
|
|
(*self).call_mut(args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 02:48:07 -05:00
|
|
|
}
|
|
|
|
pub use self::function::{Fn, FnMut, FnOnce};
|
|
|
|
// endregion:fn
|
2021-08-04 13:00:45 -05:00
|
|
|
// region:try
|
|
|
|
mod try_ {
|
2023-03-08 11:28:52 -06:00
|
|
|
use super::super::convert::Infallible;
|
|
|
|
|
2021-08-04 13:00:45 -05:00
|
|
|
pub enum ControlFlow<B, C = ()> {
|
2023-03-08 11:28:52 -06:00
|
|
|
#[lang = "Continue"]
|
2021-08-04 13:00:45 -05:00
|
|
|
Continue(C),
|
2023-03-08 11:28:52 -06:00
|
|
|
#[lang = "Break"]
|
2021-08-04 13:00:45 -05:00
|
|
|
Break(B),
|
|
|
|
}
|
2023-03-08 11:28:52 -06:00
|
|
|
pub trait FromResidual<R = <Self as Try>::Residual> {
|
2021-08-04 13:00:45 -05:00
|
|
|
#[lang = "from_residual"]
|
|
|
|
fn from_residual(residual: R) -> Self;
|
|
|
|
}
|
2023-01-21 11:47:37 -06:00
|
|
|
#[lang = "Try"]
|
2021-08-04 13:00:45 -05:00
|
|
|
pub trait Try: FromResidual<Self::Residual> {
|
|
|
|
type Output;
|
|
|
|
type Residual;
|
|
|
|
#[lang = "from_output"]
|
|
|
|
fn from_output(output: Self::Output) -> Self;
|
|
|
|
#[lang = "branch"]
|
|
|
|
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
|
|
|
|
}
|
2021-10-03 07:45:21 -05:00
|
|
|
|
|
|
|
impl<B, C> Try for ControlFlow<B, C> {
|
|
|
|
type Output = C;
|
2023-03-08 11:28:52 -06:00
|
|
|
type Residual = ControlFlow<B, Infallible>;
|
2023-04-18 09:08:38 -05:00
|
|
|
fn from_output(output: Self::Output) -> Self {
|
|
|
|
ControlFlow::Continue(output)
|
|
|
|
}
|
|
|
|
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
|
|
|
|
match self {
|
|
|
|
ControlFlow::Continue(x) => ControlFlow::Continue(x),
|
|
|
|
ControlFlow::Break(x) => ControlFlow::Break(ControlFlow::Break(x)),
|
|
|
|
}
|
|
|
|
}
|
2021-10-03 07:45:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<B, C> FromResidual for ControlFlow<B, C> {
|
2023-04-18 09:08:38 -05:00
|
|
|
fn from_residual(residual: ControlFlow<B, Infallible>) -> Self {
|
|
|
|
match residual {
|
|
|
|
ControlFlow::Break(b) => ControlFlow::Break(b),
|
|
|
|
ControlFlow::Continue(_) => loop {},
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 11:28:52 -06:00
|
|
|
}
|
|
|
|
// region:option
|
|
|
|
impl<T> Try for Option<T> {
|
|
|
|
type Output = T;
|
|
|
|
type Residual = Option<Infallible>;
|
|
|
|
fn from_output(output: Self::Output) -> Self {
|
|
|
|
Some(output)
|
|
|
|
}
|
|
|
|
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
|
|
|
|
match self {
|
|
|
|
Some(x) => ControlFlow::Continue(x),
|
|
|
|
None => ControlFlow::Break(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> FromResidual for Option<T> {
|
|
|
|
fn from_residual(x: Option<Infallible>) -> Self {
|
|
|
|
match x {
|
|
|
|
None => None,
|
2023-04-18 09:08:38 -05:00
|
|
|
Some(_) => loop {},
|
2023-03-08 11:28:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:option
|
|
|
|
// region:result
|
|
|
|
// region:from
|
|
|
|
use super::super::convert::From;
|
|
|
|
|
|
|
|
impl<T, E> Try for Result<T, E> {
|
|
|
|
type Output = T;
|
|
|
|
type Residual = Result<Infallible, E>;
|
|
|
|
|
|
|
|
fn from_output(output: Self::Output) -> Self {
|
|
|
|
Ok(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
|
|
|
|
match self {
|
|
|
|
Ok(v) => ControlFlow::Continue(v),
|
|
|
|
Err(e) => ControlFlow::Break(Err(e)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {
|
|
|
|
fn from_residual(residual: Result<Infallible, E>) -> Self {
|
|
|
|
match residual {
|
|
|
|
Err(e) => Err(From::from(e)),
|
2023-04-18 09:08:38 -05:00
|
|
|
Ok(_) => loop {},
|
2023-03-08 11:28:52 -06:00
|
|
|
}
|
|
|
|
}
|
2021-10-03 07:45:21 -05:00
|
|
|
}
|
2023-03-08 11:28:52 -06:00
|
|
|
// endregion:from
|
|
|
|
// endregion:result
|
2021-08-04 13:00:45 -05:00
|
|
|
}
|
|
|
|
pub use self::try_::{ControlFlow, FromResidual, Try};
|
|
|
|
// endregion:try
|
2021-08-22 10:21:47 -05:00
|
|
|
|
|
|
|
// region:add
|
|
|
|
#[lang = "add"]
|
|
|
|
pub trait Add<Rhs = Self> {
|
|
|
|
type Output;
|
|
|
|
fn add(self, rhs: Rhs) -> Self::Output;
|
|
|
|
}
|
2023-01-02 16:16:09 -06:00
|
|
|
|
|
|
|
#[lang = "add_assign"]
|
|
|
|
#[const_trait]
|
|
|
|
pub trait AddAssign<Rhs = Self> {
|
|
|
|
fn add_assign(&mut self, rhs: Rhs);
|
|
|
|
}
|
2023-06-03 16:33:32 -05:00
|
|
|
|
|
|
|
// 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
|
2021-08-22 10:21:47 -05:00
|
|
|
// endregion:add
|
2022-09-09 01:27:25 -05:00
|
|
|
|
2023-12-25 16:12:45 -06:00
|
|
|
// region:coroutine
|
|
|
|
mod coroutine {
|
2022-09-09 01:27:25 -05:00
|
|
|
use crate::pin::Pin;
|
|
|
|
|
2023-12-25 16:12:45 -06:00
|
|
|
#[lang = "coroutine"]
|
|
|
|
pub trait Coroutine<R = ()> {
|
2022-09-09 01:27:25 -05:00
|
|
|
type Yield;
|
2023-12-25 16:12:45 -06:00
|
|
|
#[lang = "coroutine_return"]
|
2022-09-09 01:27:25 -05:00
|
|
|
type Return;
|
2023-12-25 16:12:45 -06:00
|
|
|
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
|
2022-09-09 01:27:25 -05:00
|
|
|
}
|
|
|
|
|
2023-12-25 16:12:45 -06:00
|
|
|
#[lang = "coroutine_state"]
|
|
|
|
pub enum CoroutineState<Y, R> {
|
2022-09-09 01:27:25 -05:00
|
|
|
Yielded(Y),
|
|
|
|
Complete(R),
|
|
|
|
}
|
|
|
|
}
|
2023-12-25 16:12:45 -06:00
|
|
|
pub use self::coroutine::{Coroutine, CoroutineState};
|
|
|
|
// endregion:coroutine
|
2021-06-15 13:34:26 -05:00
|
|
|
}
|
|
|
|
|
2021-06-17 16:30:22 -05:00
|
|
|
// region:eq
|
|
|
|
pub mod cmp {
|
|
|
|
#[lang = "eq"]
|
|
|
|
pub trait PartialEq<Rhs: ?Sized = Self> {
|
|
|
|
fn eq(&self, other: &Rhs) -> bool;
|
2022-07-19 23:26:50 -05:00
|
|
|
fn ne(&self, other: &Rhs) -> bool {
|
|
|
|
!self.eq(other)
|
|
|
|
}
|
2021-06-17 16:30:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Eq: PartialEq<Self> {}
|
|
|
|
|
|
|
|
// 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<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
|
|
|
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Ord: Eq + PartialOrd<Self> {
|
|
|
|
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
|
|
|
|
|
2021-08-08 11:58:42 -05:00
|
|
|
// region:fmt
|
|
|
|
pub mod fmt {
|
|
|
|
pub struct Error;
|
|
|
|
pub type Result = Result<(), Error>;
|
|
|
|
pub struct Formatter<'a>;
|
2023-05-12 04:06:57 -05:00
|
|
|
pub struct DebugTuple;
|
|
|
|
pub struct DebugStruct;
|
|
|
|
impl Formatter<'_> {
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn debug_tuple(&mut self, _name: &str) -> DebugTuple {
|
2023-05-12 04:06:57 -05:00
|
|
|
DebugTuple
|
|
|
|
}
|
|
|
|
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn debug_struct(&mut self, _name: &str) -> DebugStruct {
|
2023-05-12 04:06:57 -05:00
|
|
|
DebugStruct
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DebugTuple {
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn field(&mut self, _value: &dyn Debug) -> &mut Self {
|
2023-05-12 04:06:57 -05:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn finish(&mut self) -> Result {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DebugStruct {
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn field(&mut self, _name: &str, _value: &dyn Debug) -> &mut Self {
|
2023-05-12 04:06:57 -05:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn finish(&mut self) -> Result {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-08 11:58:42 -05:00
|
|
|
pub trait Debug {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
|
|
|
|
}
|
2022-12-04 13:12:11 -06:00
|
|
|
pub trait Display {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
|
|
|
|
}
|
2023-05-03 05:44:47 -05:00
|
|
|
|
2023-09-06 08:21:41 -05:00
|
|
|
mod rt {
|
2023-05-18 10:00:49 -05:00
|
|
|
|
2023-09-06 08:21:41 -05:00
|
|
|
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) } }
|
|
|
|
}
|
2024-02-01 03:02:19 -06:00
|
|
|
|
|
|
|
pub fn new_display<'b, T: Display>(x: &'b T) -> Argument<'_> {
|
|
|
|
Self::new(x, Display::fmt)
|
|
|
|
}
|
2023-09-06 08:21:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "format_alignment"]
|
|
|
|
pub enum Alignment {
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
Center,
|
|
|
|
Unknown,
|
|
|
|
}
|
2023-05-18 10:00:49 -05:00
|
|
|
|
2023-09-06 08:21:41 -05:00
|
|
|
#[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;
|
2023-05-18 10:00:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "format_arguments"]
|
|
|
|
pub struct Arguments<'a> {
|
|
|
|
pieces: &'a [&'static str],
|
2023-09-06 08:21:41 -05:00
|
|
|
fmt: Option<&'a [rt::Placeholder]>,
|
|
|
|
args: &'a [rt::Argument<'a>],
|
2023-05-18 10:00:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Arguments<'a> {
|
2023-06-13 23:33:37 -05:00
|
|
|
pub const fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
|
2023-09-06 08:21:41 -05:00
|
|
|
Arguments { pieces, fmt: None, args }
|
|
|
|
}
|
|
|
|
|
2024-01-30 02:51:28 -06:00
|
|
|
pub const fn new_const(pieces: &'a [&'static str]) -> Arguments<'a> {
|
|
|
|
Arguments { pieces, fmt: None, args: &[] }
|
|
|
|
}
|
|
|
|
|
2023-09-06 08:21:41 -05:00
|
|
|
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 }
|
2023-05-18 10:00:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 05:44:47 -05:00
|
|
|
// region:derive
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
pub macro Debug($item:item) {}
|
|
|
|
// endregion:derive
|
2023-05-12 04:06:57 -05:00
|
|
|
|
|
|
|
// region:builtin_impls
|
|
|
|
macro_rules! impl_debug {
|
|
|
|
($($t:ty)*) => {
|
|
|
|
$(
|
|
|
|
impl const Debug for $t {
|
2023-09-24 15:15:36 -05:00
|
|
|
fn fmt(&self, _f: &mut Formatter<'_>) -> Result {
|
2023-05-12 04:06:57 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_debug! {
|
|
|
|
usize u8 u16 u32 u64 u128
|
|
|
|
isize i8 i16 i32 i64 i128
|
|
|
|
f32 f64
|
|
|
|
bool char
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Debug> Debug for [T] {
|
2023-09-24 15:15:36 -05:00
|
|
|
fn fmt(&self, _f: &mut Formatter<'_>) -> Result {
|
2023-05-12 04:06:57 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Debug + ?Sized> Debug for &T {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
|
|
|
(&**self).fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:builtin_impls
|
2021-08-08 11:58:42 -05:00
|
|
|
}
|
|
|
|
// endregion:fmt
|
|
|
|
|
2021-06-15 13:34:26 -05:00
|
|
|
// region:slice
|
|
|
|
pub mod slice {
|
|
|
|
#[lang = "slice"]
|
|
|
|
impl<T> [T] {
|
2023-02-03 05:16:25 -06:00
|
|
|
#[lang = "slice_len_fn"]
|
2021-06-15 13:45:25 -05:00
|
|
|
pub fn len(&self) -> usize {
|
|
|
|
loop {}
|
|
|
|
}
|
2021-06-15 13:34:26 -05:00
|
|
|
}
|
2021-06-15 13:02:40 -05:00
|
|
|
}
|
2021-06-15 13:34:26 -05:00
|
|
|
// endregion:slice
|
2021-06-15 13:02:40 -05:00
|
|
|
|
2021-06-15 14:59:51 -05:00
|
|
|
// region:option
|
|
|
|
pub mod option {
|
|
|
|
pub enum Option<T> {
|
|
|
|
#[lang = "None"]
|
|
|
|
None,
|
|
|
|
#[lang = "Some"]
|
|
|
|
Some(T),
|
|
|
|
}
|
2021-07-05 07:24:25 -05:00
|
|
|
|
2023-12-01 06:46:46 -06:00
|
|
|
// region:copy
|
|
|
|
impl<T: Copy> Copy for Option<T> {}
|
|
|
|
// endregion:copy
|
|
|
|
|
2021-07-05 07:24:25 -05:00
|
|
|
impl<T> Option<T> {
|
|
|
|
pub const fn unwrap(self) -> T {
|
|
|
|
match self {
|
|
|
|
Some(val) => val,
|
|
|
|
None => panic!("called `Option::unwrap()` on a `None` value"),
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 15:17:16 -06:00
|
|
|
|
2023-06-02 05:17:02 -05:00
|
|
|
pub const fn as_ref(&self) -> Option<&T> {
|
|
|
|
match self {
|
|
|
|
Some(x) => Some(x),
|
|
|
|
None => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn and<U>(self, _optb: Option<U>) -> Option<U> {
|
2023-03-06 15:17:16 -06:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
pub fn unwrap_or(self, default: T) -> T {
|
2023-03-14 14:31:46 -05:00
|
|
|
match self {
|
|
|
|
Some(val) => val,
|
|
|
|
None => default,
|
|
|
|
}
|
2023-03-06 15:17:16 -06:00
|
|
|
}
|
2023-04-28 12:14:30 -05:00
|
|
|
// region:result
|
|
|
|
pub const fn ok_or<E>(self, err: E) -> Result<T, E> {
|
|
|
|
match self {
|
|
|
|
Some(v) => Ok(v),
|
|
|
|
None => Err(err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:result
|
2023-03-06 15:17:16 -06:00
|
|
|
// region:fn
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn and_then<U, F>(self, _f: F) -> Option<U>
|
2023-03-06 15:17:16 -06:00
|
|
|
where
|
|
|
|
F: FnOnce(T) -> Option<U>,
|
|
|
|
{
|
|
|
|
loop {}
|
|
|
|
}
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn unwrap_or_else<F>(self, _f: F) -> T
|
2023-03-06 15:17:16 -06:00
|
|
|
where
|
|
|
|
F: FnOnce() -> T,
|
|
|
|
{
|
|
|
|
loop {}
|
|
|
|
}
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn map_or<U, F>(self, _default: U, _f: F) -> U
|
2023-03-06 15:17:16 -06:00
|
|
|
where
|
|
|
|
F: FnOnce(T) -> U,
|
|
|
|
{
|
|
|
|
loop {}
|
|
|
|
}
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn map_or_else<U, D, F>(self, _default: D, _f: F) -> U
|
2023-03-06 15:17:16 -06:00
|
|
|
where
|
|
|
|
D: FnOnce() -> U,
|
|
|
|
F: FnOnce(T) -> U,
|
|
|
|
{
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
// endregion:fn
|
2021-07-05 07:24:25 -05:00
|
|
|
}
|
2021-06-15 14:59:51 -05:00
|
|
|
}
|
|
|
|
// endregion:option
|
|
|
|
|
2021-06-15 15:07:25 -05:00
|
|
|
// region:result
|
|
|
|
pub mod result {
|
|
|
|
pub enum Result<T, E> {
|
|
|
|
#[lang = "Ok"]
|
|
|
|
Ok(T),
|
|
|
|
#[lang = "Err"]
|
|
|
|
Err(E),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:result
|
|
|
|
|
2021-06-15 14:49:00 -05:00
|
|
|
// region:pin
|
|
|
|
pub mod pin {
|
|
|
|
#[lang = "pin"]
|
|
|
|
#[fundamental]
|
|
|
|
pub struct Pin<P> {
|
|
|
|
pointer: P,
|
|
|
|
}
|
2022-09-09 01:27:25 -05:00
|
|
|
impl<P> Pin<P> {
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn new(_pointer: P) -> Pin<P> {
|
2022-09-09 01:27:25 -05:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// region:deref
|
|
|
|
impl<P: crate::ops::Deref> crate::ops::Deref for Pin<P> {
|
|
|
|
type Target = P::Target;
|
|
|
|
fn deref(&self) -> &P::Target {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:deref
|
2021-06-15 14:49:00 -05:00
|
|
|
}
|
|
|
|
// endregion:pin
|
|
|
|
|
|
|
|
// region:future
|
|
|
|
pub mod future {
|
2021-06-15 14:59:51 -05:00
|
|
|
use crate::{
|
|
|
|
pin::Pin,
|
|
|
|
task::{Context, Poll},
|
|
|
|
};
|
2021-06-15 14:49:00 -05:00
|
|
|
|
2024-01-16 09:15:56 -06:00
|
|
|
#[doc(notable_trait)]
|
2021-06-15 14:49:00 -05:00
|
|
|
#[lang = "future_trait"]
|
|
|
|
pub trait Future {
|
|
|
|
type Output;
|
|
|
|
#[lang = "poll"]
|
|
|
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>;
|
|
|
|
}
|
2022-08-08 19:20:45 -05:00
|
|
|
|
|
|
|
pub trait IntoFuture {
|
|
|
|
type Output;
|
|
|
|
type IntoFuture: Future<Output = Self::Output>;
|
|
|
|
#[lang = "into_future"]
|
|
|
|
fn into_future(self) -> Self::IntoFuture;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<F: Future> IntoFuture for F {
|
|
|
|
type Output = F::Output;
|
|
|
|
type IntoFuture = F;
|
|
|
|
fn into_future(self) -> F {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2021-06-15 14:49:00 -05:00
|
|
|
}
|
|
|
|
pub mod task {
|
|
|
|
pub enum Poll<T> {
|
|
|
|
#[lang = "Ready"]
|
|
|
|
Ready(T),
|
|
|
|
#[lang = "Pending"]
|
|
|
|
Pending,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Context<'a> {
|
|
|
|
waker: &'a (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:future
|
|
|
|
|
2021-06-16 14:48:48 -05:00
|
|
|
// region:iterator
|
|
|
|
pub mod iter {
|
2021-06-17 03:28:44 -05:00
|
|
|
// region:iterators
|
2021-06-16 15:27:04 -05:00
|
|
|
mod adapters {
|
|
|
|
pub struct Take<I> {
|
|
|
|
iter: I,
|
|
|
|
n: usize,
|
|
|
|
}
|
|
|
|
impl<I> Iterator for Take<I>
|
|
|
|
where
|
|
|
|
I: Iterator,
|
|
|
|
{
|
|
|
|
type Item = <I as Iterator>::Item;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<<I as Iterator>::Item> {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 15:48:18 -05:00
|
|
|
|
|
|
|
pub struct FilterMap<I, F> {
|
|
|
|
iter: I,
|
|
|
|
f: F,
|
|
|
|
}
|
|
|
|
impl<B, I: Iterator, F> Iterator for FilterMap<I, F>
|
|
|
|
where
|
|
|
|
F: FnMut(I::Item) -> Option<B>,
|
|
|
|
{
|
|
|
|
type Item = B;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn next(&mut self) -> Option<B> {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 15:27:04 -05:00
|
|
|
}
|
2022-10-06 07:31:06 -05:00
|
|
|
pub use self::adapters::{FilterMap, Take};
|
2021-06-16 15:27:04 -05:00
|
|
|
|
2021-06-17 03:18:37 -05:00
|
|
|
mod sources {
|
|
|
|
mod repeat {
|
2023-09-24 15:15:36 -05:00
|
|
|
pub fn repeat<T>(_elt: T) -> Repeat<T> {
|
2021-06-17 03:18:37 -05:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Repeat<A> {
|
|
|
|
element: A,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A> Iterator for Repeat<A> {
|
|
|
|
type Item = A;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<A> {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub use self::repeat::{repeat, Repeat};
|
|
|
|
}
|
|
|
|
pub use self::sources::{repeat, Repeat};
|
2021-06-17 03:28:44 -05:00
|
|
|
// endregion:iterators
|
2021-06-17 03:18:37 -05:00
|
|
|
|
2021-06-16 14:48:48 -05:00
|
|
|
mod traits {
|
|
|
|
mod iterator {
|
2024-01-16 09:15:56 -06:00
|
|
|
#[doc(notable_trait)]
|
2021-06-16 14:48:48 -05:00
|
|
|
pub trait Iterator {
|
|
|
|
type Item;
|
|
|
|
#[lang = "next"]
|
|
|
|
fn next(&mut self) -> Option<Self::Item>;
|
|
|
|
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
|
|
|
loop {}
|
|
|
|
}
|
2021-06-17 03:18:37 -05:00
|
|
|
fn by_ref(&mut self) -> &mut Self
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
self
|
|
|
|
}
|
2021-06-17 03:28:44 -05:00
|
|
|
// region:iterators
|
|
|
|
fn take(self, n: usize) -> crate::iter::Take<Self> {
|
|
|
|
loop {}
|
|
|
|
}
|
2023-09-24 15:15:36 -05:00
|
|
|
fn filter_map<B, F>(self, _f: F) -> crate::iter::FilterMap<Self, F>
|
2021-06-18 15:48:18 -05:00
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
F: FnMut(Self::Item) -> Option<B>,
|
|
|
|
{
|
|
|
|
loop {}
|
|
|
|
}
|
2021-06-17 03:28:44 -05:00
|
|
|
// endregion:iterators
|
2021-06-17 03:18:37 -05:00
|
|
|
}
|
|
|
|
impl<I: Iterator + ?Sized> Iterator for &mut I {
|
|
|
|
type Item = I::Item;
|
|
|
|
fn next(&mut self) -> Option<I::Item> {
|
|
|
|
(**self).next()
|
|
|
|
}
|
2021-06-16 14:48:48 -05:00
|
|
|
}
|
|
|
|
}
|
2021-06-16 15:27:04 -05:00
|
|
|
pub use self::iterator::Iterator;
|
|
|
|
|
2021-06-16 14:48:48 -05:00
|
|
|
mod collect {
|
|
|
|
pub trait IntoIterator {
|
|
|
|
type Item;
|
|
|
|
type IntoIter: Iterator<Item = Self::Item>;
|
|
|
|
#[lang = "into_iter"]
|
|
|
|
fn into_iter(self) -> Self::IntoIter;
|
|
|
|
}
|
2021-06-16 14:54:57 -05:00
|
|
|
impl<I: Iterator> IntoIterator for I {
|
|
|
|
type Item = I::Item;
|
|
|
|
type IntoIter = I;
|
|
|
|
fn into_iter(self) -> I {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2023-04-10 20:02:11 -05:00
|
|
|
struct IndexRange {
|
|
|
|
start: usize,
|
|
|
|
end: usize,
|
|
|
|
}
|
|
|
|
pub struct IntoIter<T, const N: usize> {
|
|
|
|
data: [T; N],
|
|
|
|
range: IndexRange,
|
|
|
|
}
|
2023-03-02 01:48:50 -06:00
|
|
|
impl<T, const N: usize> IntoIterator for [T; N] {
|
|
|
|
type Item = T;
|
|
|
|
type IntoIter = IntoIter<T, N>;
|
|
|
|
fn into_iter(self) -> I {
|
2023-04-18 09:08:38 -05:00
|
|
|
IntoIter { data: self, range: IndexRange { start: 0, end: loop {} } }
|
2023-03-02 01:48:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<T, const N: usize> Iterator for IntoIter<T, N> {
|
|
|
|
type Item = T;
|
|
|
|
fn next(&mut self) -> Option<T> {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 14:48:48 -05:00
|
|
|
}
|
|
|
|
pub use self::collect::IntoIterator;
|
|
|
|
}
|
|
|
|
pub use self::traits::{IntoIterator, Iterator};
|
|
|
|
}
|
|
|
|
// endregion:iterator
|
|
|
|
|
2023-04-18 09:08:38 -05:00
|
|
|
// region:panic
|
|
|
|
mod panic {
|
2023-05-18 10:00:49 -05:00
|
|
|
pub macro panic_2021 {
|
2024-01-30 02:51:28 -06:00
|
|
|
() => (
|
|
|
|
$crate::panicking::panic("explicit panic")
|
|
|
|
),
|
2023-05-18 10:00:49 -05:00
|
|
|
($($t:tt)+) => (
|
|
|
|
$crate::panicking::panic_fmt($crate::const_format_args!($($t)+))
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod panicking {
|
|
|
|
#[lang = "panic_fmt"]
|
2023-09-24 15:15:36 -05:00
|
|
|
pub const fn panic_fmt(_fmt: crate::fmt::Arguments<'_>) -> ! {
|
2023-05-18 10:00:49 -05:00
|
|
|
loop {}
|
2023-04-18 09:08:38 -05:00
|
|
|
}
|
2024-01-30 02:51:28 -06:00
|
|
|
|
|
|
|
#[lang = "panic"]
|
|
|
|
pub const fn panic(expr: &'static str) -> ! {
|
|
|
|
panic_fmt(crate::fmt::Arguments::new_const(&[expr]))
|
|
|
|
}
|
2023-04-18 09:08:38 -05:00
|
|
|
}
|
|
|
|
// endregion:panic
|
|
|
|
|
2021-06-17 16:30:22 -05:00
|
|
|
mod macros {
|
2023-04-18 09:08:38 -05:00
|
|
|
// region:panic
|
|
|
|
#[macro_export]
|
2023-12-02 09:50:21 -06:00
|
|
|
#[rustc_builtin_macro(core_panic)]
|
2023-04-18 09:08:38 -05:00
|
|
|
macro_rules! panic {
|
|
|
|
($($arg:tt)*) => {
|
|
|
|
/* compiler built-in */
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// endregion:panic
|
|
|
|
|
2023-12-05 09:30:57 -06:00
|
|
|
// region:asm
|
|
|
|
#[macro_export]
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro_rules! asm {
|
|
|
|
($($arg:tt)*) => {
|
|
|
|
/* compiler built-in */
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// endregion:asm
|
|
|
|
|
|
|
|
// region:assert
|
|
|
|
#[macro_export]
|
|
|
|
#[rustc_builtin_macro]
|
2023-12-21 09:20:27 -06:00
|
|
|
#[allow_internal_unstable(core_panic, edition_panic, generic_assert_internals)]
|
2023-12-05 09:30:57 -06:00
|
|
|
macro_rules! assert {
|
|
|
|
($($arg:tt)*) => {
|
|
|
|
/* compiler built-in */
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// endregion:assert
|
|
|
|
|
2023-05-18 10:00:49 -05:00
|
|
|
// region:fmt
|
2023-12-21 09:20:27 -06:00
|
|
|
#[allow_internal_unstable(fmt_internals, const_fmt_arguments_new)]
|
2023-05-18 10:00:49 -05:00
|
|
|
#[macro_export]
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro_rules! const_format_args {
|
|
|
|
($fmt:expr) => {{ /* compiler built-in */ }};
|
|
|
|
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:20:27 -06:00
|
|
|
#[allow_internal_unstable(fmt_internals)]
|
2023-09-06 11:00:30 -05:00
|
|
|
#[macro_export]
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro_rules! format_args {
|
|
|
|
($fmt:expr) => {{ /* compiler built-in */ }};
|
|
|
|
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:20:27 -06:00
|
|
|
#[allow_internal_unstable(fmt_internals)]
|
2023-12-05 09:30:57 -06:00
|
|
|
#[macro_export]
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
macro_rules! format_args_nl {
|
|
|
|
($fmt:expr) => {{ /* compiler built-in */ }};
|
|
|
|
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
|
|
|
|
}
|
|
|
|
|
2023-09-06 11:00:30 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! print {
|
|
|
|
($($arg:tt)*) => {{
|
|
|
|
$crate::io::_print($crate::format_args!($($arg)*));
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2023-05-18 10:00:49 -05:00
|
|
|
// endregion:fmt
|
|
|
|
|
2024-02-01 03:02:19 -06:00
|
|
|
// 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
|
|
|
|
|
|
|
|
|
2023-04-18 09:08:38 -05:00
|
|
|
// region:derive
|
2021-06-17 16:30:22 -05:00
|
|
|
pub(crate) mod builtin {
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
pub macro derive($item:item) {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2023-06-29 12:28:35 -05:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
pub macro derive_const($item:item) {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2021-06-17 16:30:22 -05:00
|
|
|
}
|
2023-04-18 09:08:38 -05:00
|
|
|
// endregion:derive
|
2023-06-04 03:02:11 -05:00
|
|
|
|
|
|
|
// region:include
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! include {
|
|
|
|
($file:expr $(,)?) => {{ /* compiler built-in */ }};
|
|
|
|
}
|
|
|
|
// endregion:include
|
2023-12-02 09:50:21 -06:00
|
|
|
|
|
|
|
// region:concat
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! concat {}
|
|
|
|
// endregion:concat
|
2024-01-08 03:37:09 -06:00
|
|
|
|
|
|
|
// region:env
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! env {}
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! option_env {}
|
|
|
|
// endregion:env
|
2021-06-17 16:30:22 -05:00
|
|
|
}
|
|
|
|
|
2022-10-27 14:58:34 -05:00
|
|
|
// 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
|
|
|
|
|
2021-08-10 06:03:12 -05:00
|
|
|
// region:bool_impl
|
|
|
|
#[lang = "bool"]
|
|
|
|
impl bool {
|
|
|
|
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
|
|
|
|
if self {
|
|
|
|
Some(f())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion:bool_impl
|
|
|
|
|
2023-06-05 06:27:19 -05:00
|
|
|
// region:int_impl
|
|
|
|
macro_rules! impl_int {
|
|
|
|
($($t:ty)*) => {
|
|
|
|
$(
|
|
|
|
impl $t {
|
|
|
|
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
|
|
|
|
unsafe { mem::transmute(bytes) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_int! {
|
|
|
|
usize u8 u16 u32 u64 u128
|
|
|
|
isize i8 i16 i32 i64 i128
|
|
|
|
}
|
|
|
|
// endregion:int_impl
|
|
|
|
|
2022-12-04 13:12:11 -06:00
|
|
|
// 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
|
|
|
|
|
2021-06-15 13:02:40 -05:00
|
|
|
pub mod prelude {
|
|
|
|
pub mod v1 {
|
2021-06-15 15:07:25 -05:00
|
|
|
pub use crate::{
|
2023-06-29 12:28:35 -05:00
|
|
|
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
|
2021-06-15 15:07:25 -05:00
|
|
|
};
|
2021-06-15 13:02:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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::*;
|