2019-07-28 02:24:16 -05:00
|
|
|
#![feature(
|
2022-03-20 10:55:21 -05:00
|
|
|
no_core,
|
|
|
|
lang_items,
|
|
|
|
intrinsics,
|
|
|
|
unboxed_closures,
|
|
|
|
extern_types,
|
|
|
|
decl_macro,
|
|
|
|
rustc_attrs,
|
|
|
|
transparent_unions,
|
|
|
|
auto_traits,
|
2024-02-23 06:11:11 -06:00
|
|
|
freeze_impls,
|
2022-03-20 10:55:21 -05:00
|
|
|
thread_local
|
2019-07-28 02:24:16 -05:00
|
|
|
)]
|
2018-07-24 07:10:53 -05:00
|
|
|
#![no_core]
|
2023-11-09 11:13:52 -06:00
|
|
|
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
|
2018-07-24 07:10:53 -05:00
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "sized"]
|
2018-07-24 07:10:53 -05:00
|
|
|
pub trait Sized {}
|
|
|
|
|
2022-04-22 14:11:38 -05:00
|
|
|
#[lang = "destruct"]
|
|
|
|
pub trait Destruct {}
|
|
|
|
|
2022-12-14 12:30:46 -06:00
|
|
|
#[lang = "tuple_trait"]
|
|
|
|
pub trait Tuple {}
|
|
|
|
|
2018-07-30 10:29:39 -05:00
|
|
|
#[lang = "unsize"]
|
|
|
|
pub trait Unsize<T: ?Sized> {}
|
|
|
|
|
|
|
|
#[lang = "coerce_unsized"]
|
|
|
|
pub trait CoerceUnsized<T> {}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
2018-12-29 08:33:34 -06:00
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
|
2018-09-16 07:49:45 -05:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
2018-09-16 04:57:27 -05:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
2018-07-30 10:29:39 -05:00
|
|
|
|
2018-11-03 12:22:05 -05:00
|
|
|
#[lang = "dispatch_from_dyn"]
|
|
|
|
pub trait DispatchFromDyn<T> {}
|
|
|
|
|
|
|
|
// &T -> &U
|
2023-04-29 07:00:43 -05:00
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
|
2018-11-03 12:22:05 -05:00
|
|
|
// &mut T -> &mut U
|
2023-04-29 07:00:43 -05:00
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
|
2018-11-03 12:22:05 -05:00
|
|
|
// *const T -> *const U
|
2023-04-29 07:00:43 -05:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
|
2018-11-03 12:22:05 -05:00
|
|
|
// *mut T -> *mut U
|
2023-04-29 07:00:43 -05:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
|
2019-03-02 14:09:28 -06:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
|
2018-11-03 12:22:05 -05:00
|
|
|
|
2018-12-24 07:50:18 -06:00
|
|
|
#[lang = "receiver"]
|
|
|
|
pub trait Receiver {}
|
|
|
|
|
|
|
|
impl<T: ?Sized> Receiver for &T {}
|
|
|
|
impl<T: ?Sized> Receiver for &mut T {}
|
|
|
|
impl<T: ?Sized> Receiver for Box<T> {}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "copy"]
|
2018-07-24 07:10:53 -05:00
|
|
|
pub unsafe trait Copy {}
|
|
|
|
|
2018-07-26 03:59:57 -05:00
|
|
|
unsafe impl Copy for bool {}
|
2018-07-24 07:10:53 -05:00
|
|
|
unsafe impl Copy for u8 {}
|
|
|
|
unsafe impl Copy for u16 {}
|
|
|
|
unsafe impl Copy for u32 {}
|
|
|
|
unsafe impl Copy for u64 {}
|
2020-11-03 04:00:04 -06:00
|
|
|
unsafe impl Copy for u128 {}
|
2018-07-24 07:10:53 -05:00
|
|
|
unsafe impl Copy for usize {}
|
|
|
|
unsafe impl Copy for i8 {}
|
|
|
|
unsafe impl Copy for i16 {}
|
|
|
|
unsafe impl Copy for i32 {}
|
|
|
|
unsafe impl Copy for isize {}
|
2019-08-12 10:25:16 -05:00
|
|
|
unsafe impl Copy for f32 {}
|
2022-03-20 10:55:21 -05:00
|
|
|
unsafe impl Copy for f64 {}
|
2018-07-26 03:48:50 -05:00
|
|
|
unsafe impl Copy for char {}
|
2018-07-24 07:10:53 -05:00
|
|
|
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
|
|
|
|
unsafe impl<T: ?Sized> Copy for *const T {}
|
2019-01-26 08:10:21 -06:00
|
|
|
unsafe impl<T: ?Sized> Copy for *mut T {}
|
2020-09-14 04:32:18 -05:00
|
|
|
unsafe impl<T: Copy> Copy for Option<T> {}
|
2018-07-24 07:10:53 -05:00
|
|
|
|
2018-08-09 04:41:34 -05:00
|
|
|
#[lang = "sync"]
|
|
|
|
pub unsafe trait Sync {}
|
|
|
|
|
|
|
|
unsafe impl Sync for bool {}
|
|
|
|
unsafe impl Sync for u8 {}
|
|
|
|
unsafe impl Sync for u16 {}
|
|
|
|
unsafe impl Sync for u32 {}
|
|
|
|
unsafe impl Sync for u64 {}
|
|
|
|
unsafe impl Sync for usize {}
|
|
|
|
unsafe impl Sync for i8 {}
|
|
|
|
unsafe impl Sync for i16 {}
|
|
|
|
unsafe impl Sync for i32 {}
|
|
|
|
unsafe impl Sync for isize {}
|
|
|
|
unsafe impl Sync for char {}
|
2024-03-27 15:43:19 -05:00
|
|
|
unsafe impl Sync for f32 {}
|
2018-08-13 12:02:42 -05:00
|
|
|
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
|
2024-03-27 15:43:19 -05:00
|
|
|
unsafe impl<T: Sync, const N: usize> Sync for [T; N] {}
|
2018-08-09 04:41:34 -05:00
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "freeze"]
|
2019-12-05 14:00:57 -06:00
|
|
|
unsafe auto trait Freeze {}
|
|
|
|
|
|
|
|
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
|
|
|
|
unsafe impl<T: ?Sized> Freeze for *const T {}
|
|
|
|
unsafe impl<T: ?Sized> Freeze for *mut T {}
|
|
|
|
unsafe impl<T: ?Sized> Freeze for &T {}
|
|
|
|
unsafe impl<T: ?Sized> Freeze for &mut T {}
|
2018-07-24 07:10:53 -05:00
|
|
|
|
2020-04-30 04:28:48 -05:00
|
|
|
#[lang = "structural_peq"]
|
|
|
|
pub trait StructuralPartialEq {}
|
|
|
|
|
2018-09-14 12:49:33 -05:00
|
|
|
#[lang = "not"]
|
|
|
|
pub trait Not {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn not(self) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Not for bool {
|
|
|
|
type Output = bool;
|
|
|
|
|
|
|
|
fn not(self) -> bool {
|
|
|
|
!self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "mul"]
|
2018-07-24 07:10:53 -05:00
|
|
|
pub trait Mul<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
fn mul(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Mul for u8 {
|
|
|
|
type Output = Self;
|
|
|
|
|
2018-08-13 08:56:01 -05:00
|
|
|
fn mul(self, rhs: Self) -> Self::Output {
|
2018-07-24 07:10:53 -05:00
|
|
|
self * rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:53:18 -06:00
|
|
|
impl Mul for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn mul(self, rhs: Self) -> Self::Output {
|
|
|
|
self * rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 12:14:55 -05:00
|
|
|
#[lang = "add"]
|
|
|
|
pub trait Add<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn add(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Add for u8 {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
|
|
self + rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-13 09:55:08 -05:00
|
|
|
impl Add for i8 {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
|
|
self + rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 08:10:21 -06:00
|
|
|
impl Add for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
|
|
self + rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:56:01 -05:00
|
|
|
#[lang = "sub"]
|
|
|
|
pub trait Sub<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn sub(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
|
|
|
self - rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-13 09:55:08 -05:00
|
|
|
impl Sub for u8 {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
|
|
|
self - rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for i8 {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
|
|
|
self - rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Sub for i16 {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, rhs: Self) -> Self {
|
|
|
|
self - rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 12:22:43 -05:00
|
|
|
#[lang = "rem"]
|
|
|
|
pub trait Rem<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn rem(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Rem for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn rem(self, rhs: Self) -> Self {
|
|
|
|
self % rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "bitor"]
|
2018-07-26 03:59:57 -05:00
|
|
|
pub trait BitOr<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
fn bitor(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BitOr for bool {
|
|
|
|
type Output = bool;
|
|
|
|
|
|
|
|
fn bitor(self, rhs: bool) -> bool {
|
|
|
|
self | rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> BitOr<bool> for &'a bool {
|
|
|
|
type Output = bool;
|
|
|
|
|
|
|
|
fn bitor(self, rhs: bool) -> bool {
|
|
|
|
*self | rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
#[lang = "eq"]
|
|
|
|
pub trait PartialEq<Rhs: ?Sized = Self> {
|
|
|
|
fn eq(&self, other: &Rhs) -> bool;
|
|
|
|
fn ne(&self, other: &Rhs) -> bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for u8 {
|
2018-07-31 05:25:16 -05:00
|
|
|
fn eq(&self, other: &u8) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u8) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
2018-07-24 07:10:53 -05:00
|
|
|
}
|
|
|
|
|
2019-01-26 08:10:21 -06:00
|
|
|
impl PartialEq for u16 {
|
|
|
|
fn eq(&self, other: &u16) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u16) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for u32 {
|
|
|
|
fn eq(&self, other: &u32) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u32) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-17 11:52:47 -06:00
|
|
|
impl PartialEq for u64 {
|
|
|
|
fn eq(&self, other: &u64) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u64) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 04:00:04 -06:00
|
|
|
impl PartialEq for u128 {
|
|
|
|
fn eq(&self, other: &u128) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u128) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 08:10:21 -06:00
|
|
|
impl PartialEq for usize {
|
|
|
|
fn eq(&self, other: &usize) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &usize) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 10:25:16 -05:00
|
|
|
impl PartialEq for i8 {
|
|
|
|
fn eq(&self, other: &i8) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &i8) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 14:09:28 -06:00
|
|
|
impl PartialEq for i32 {
|
|
|
|
fn eq(&self, other: &i32) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &i32) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:53:18 -06:00
|
|
|
impl PartialEq for isize {
|
|
|
|
fn eq(&self, other: &isize) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &isize) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 03:48:50 -05:00
|
|
|
impl PartialEq for char {
|
2018-07-31 05:25:16 -05:00
|
|
|
fn eq(&self, other: &char) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &char) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
2018-07-26 03:48:50 -05:00
|
|
|
}
|
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
impl<T: ?Sized> PartialEq for *const T {
|
2018-07-31 05:25:16 -05:00
|
|
|
fn eq(&self, other: &*const T) -> bool {
|
|
|
|
*self == *other
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &*const T) -> bool {
|
|
|
|
*self != *other
|
|
|
|
}
|
2018-07-24 07:10:53 -05:00
|
|
|
}
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
impl<T: PartialEq> PartialEq for Option<T> {
|
2020-09-14 04:32:18 -05:00
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
match (self, other) {
|
|
|
|
(Some(lhs), Some(rhs)) => *lhs == *rhs,
|
|
|
|
(None, None) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ne(&self, other: &Self) -> bool {
|
|
|
|
match (self, other) {
|
|
|
|
(Some(lhs), Some(rhs)) => *lhs != *rhs,
|
|
|
|
(None, None) => false,
|
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 12:12:59 -06:00
|
|
|
#[lang = "shl"]
|
|
|
|
pub trait Shl<RHS = Self> {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
fn shl(self, rhs: RHS) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Shl for u128 {
|
|
|
|
type Output = u128;
|
|
|
|
|
|
|
|
fn shl(self, rhs: u128) -> u128 {
|
|
|
|
self << rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 11:02:37 -05:00
|
|
|
#[lang = "neg"]
|
|
|
|
pub trait Neg {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn neg(self) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
2019-07-13 09:55:08 -05:00
|
|
|
impl Neg for i8 {
|
|
|
|
type Output = i8;
|
|
|
|
|
|
|
|
fn neg(self) -> i8 {
|
|
|
|
-self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Neg for i16 {
|
|
|
|
type Output = i16;
|
|
|
|
|
|
|
|
fn neg(self) -> i16 {
|
2019-06-29 09:43:20 -05:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 11:02:37 -05:00
|
|
|
impl Neg for isize {
|
|
|
|
type Output = isize;
|
|
|
|
|
|
|
|
fn neg(self) -> isize {
|
|
|
|
-self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 10:25:16 -05:00
|
|
|
impl Neg for f32 {
|
|
|
|
type Output = f32;
|
|
|
|
|
|
|
|
fn neg(self) -> f32 {
|
|
|
|
-self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 09:21:07 -05:00
|
|
|
pub enum Option<T> {
|
|
|
|
Some(T),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use Option::*;
|
|
|
|
|
2018-09-16 07:49:45 -05:00
|
|
|
#[lang = "phantom_data"]
|
|
|
|
pub struct PhantomData<T: ?Sized>;
|
|
|
|
|
2018-07-20 06:38:49 -05:00
|
|
|
#[lang = "fn_once"]
|
|
|
|
#[rustc_paren_sugar]
|
2022-12-14 12:30:46 -06:00
|
|
|
pub trait FnOnce<Args: Tuple> {
|
2020-06-27 04:29:39 -05:00
|
|
|
#[lang = "fn_once_output"]
|
2018-07-20 06:38:49 -05:00
|
|
|
type Output;
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "fn_mut"]
|
|
|
|
#[rustc_paren_sugar]
|
2022-12-14 12:30:46 -06:00
|
|
|
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
|
2018-07-20 06:38:49 -05:00
|
|
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
#[lang = "panic"]
|
2020-04-25 12:07:25 -05:00
|
|
|
#[track_caller]
|
2022-07-25 09:07:57 -05:00
|
|
|
pub fn panic(_msg: &'static str) -> ! {
|
2018-09-02 08:22:04 -05:00
|
|
|
unsafe {
|
2020-06-16 04:50:58 -05:00
|
|
|
libc::puts("Panicking\n\0" as *const str as *const i8);
|
2020-04-25 12:07:25 -05:00
|
|
|
intrinsics::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 21:26:39 -05:00
|
|
|
macro_rules! panic_const {
|
|
|
|
($($lang:ident = $message:expr,)+) => {
|
|
|
|
pub mod panic_const {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
$(
|
|
|
|
#[track_caller]
|
|
|
|
#[lang = stringify!($lang)]
|
|
|
|
pub fn $lang() -> ! {
|
|
|
|
panic($message);
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic_const! {
|
|
|
|
panic_const_add_overflow = "attempt to add with overflow",
|
|
|
|
panic_const_sub_overflow = "attempt to subtract with overflow",
|
|
|
|
panic_const_mul_overflow = "attempt to multiply with overflow",
|
|
|
|
panic_const_div_overflow = "attempt to divide with overflow",
|
|
|
|
panic_const_rem_overflow = "attempt to calculate the remainder with overflow",
|
|
|
|
panic_const_neg_overflow = "attempt to negate with overflow",
|
|
|
|
panic_const_shr_overflow = "attempt to shift right with overflow",
|
|
|
|
panic_const_shl_overflow = "attempt to shift left with overflow",
|
|
|
|
panic_const_div_by_zero = "attempt to divide by zero",
|
|
|
|
panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero",
|
|
|
|
}
|
|
|
|
|
2020-04-25 12:07:25 -05:00
|
|
|
#[lang = "panic_bounds_check"]
|
|
|
|
#[track_caller]
|
|
|
|
fn panic_bounds_check(index: usize, len: usize) -> ! {
|
|
|
|
unsafe {
|
2023-04-29 07:00:43 -05:00
|
|
|
libc::printf(
|
|
|
|
"index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8,
|
|
|
|
len,
|
|
|
|
index,
|
|
|
|
);
|
|
|
|
intrinsics::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "panic_cannot_unwind"]
|
|
|
|
#[track_caller]
|
|
|
|
fn panic_cannot_unwind() -> ! {
|
|
|
|
unsafe {
|
|
|
|
libc::puts("panic in a function that cannot unwind\n\0" as *const str as *const i8);
|
2018-09-02 08:22:04 -05:00
|
|
|
intrinsics::abort();
|
|
|
|
}
|
2018-07-24 07:10:53 -05:00
|
|
|
}
|
|
|
|
|
2018-08-11 07:52:00 -05:00
|
|
|
#[lang = "eh_personality"]
|
|
|
|
fn eh_personality() -> ! {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
#[lang = "drop_in_place"]
|
|
|
|
#[allow(unconditional_recursion)]
|
|
|
|
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|
|
|
// Code here does not matter - this is replaced by the
|
|
|
|
// real drop glue by the compiler.
|
|
|
|
drop_in_place(to_drop);
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
#[lang = "unpin"]
|
|
|
|
pub auto trait Unpin {}
|
|
|
|
|
2019-03-02 14:09:28 -06:00
|
|
|
#[lang = "deref"]
|
|
|
|
pub trait Deref {
|
|
|
|
type Target: ?Sized;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target;
|
|
|
|
}
|
|
|
|
|
2022-04-22 14:11:38 -05:00
|
|
|
#[repr(transparent)]
|
|
|
|
#[rustc_layout_scalar_valid_range_start(1)]
|
|
|
|
#[rustc_nonnull_optimization_guaranteed]
|
2022-07-25 09:07:57 -05:00
|
|
|
pub struct NonNull<T: ?Sized>(pub *const T);
|
2022-04-22 14:11:38 -05:00
|
|
|
|
|
|
|
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
|
|
|
|
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
|
|
|
|
|
2022-03-20 10:55:21 -05:00
|
|
|
pub struct Unique<T: ?Sized> {
|
2022-04-22 14:11:38 -05:00
|
|
|
pub pointer: NonNull<T>,
|
2022-03-20 10:55:21 -05:00
|
|
|
pub _marker: PhantomData<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
|
|
|
|
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
|
|
|
|
|
2024-03-05 04:32:03 -06:00
|
|
|
#[lang = "global_alloc_ty"]
|
|
|
|
pub struct Global;
|
|
|
|
|
2018-09-04 12:04:25 -05:00
|
|
|
#[lang = "owned_box"]
|
2024-03-05 04:32:03 -06:00
|
|
|
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);
|
2018-09-16 04:57:27 -05:00
|
|
|
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
2018-09-04 12:04:25 -05:00
|
|
|
|
2023-03-15 09:41:48 -05:00
|
|
|
impl<T> Box<T> {
|
|
|
|
pub fn new(val: T) -> Box<T> {
|
|
|
|
unsafe {
|
|
|
|
let size = intrinsics::size_of::<T>();
|
|
|
|
let ptr = libc::malloc(size);
|
|
|
|
intrinsics::copy(&val as *const T as *const u8, ptr, size);
|
2024-03-05 04:32:03 -06:00
|
|
|
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
|
2023-03-15 09:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
impl<T: ?Sized, A> Drop for Box<T, A> {
|
2019-02-07 13:45:15 -06:00
|
|
|
fn drop(&mut self) {
|
2022-08-01 15:51:58 -05:00
|
|
|
// inner value is dropped by compiler
|
2023-07-22 08:32:34 -05:00
|
|
|
unsafe {
|
|
|
|
libc::free(self.0.pointer.0 as *mut u8);
|
|
|
|
}
|
2019-02-07 13:45:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 09:07:57 -05:00
|
|
|
impl<T: ?Sized> Deref for Box<T> {
|
2019-03-02 14:09:28 -06:00
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&**self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 12:04:25 -05:00
|
|
|
#[lang = "exchange_malloc"]
|
|
|
|
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
2019-01-26 08:10:21 -06:00
|
|
|
libc::malloc(size)
|
2018-09-04 12:04:25 -05:00
|
|
|
}
|
|
|
|
|
2018-09-11 12:27:57 -05:00
|
|
|
#[lang = "drop"]
|
|
|
|
pub trait Drop {
|
|
|
|
fn drop(&mut self);
|
|
|
|
}
|
|
|
|
|
2019-10-25 14:24:50 -05:00
|
|
|
#[lang = "manually_drop"]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct ManuallyDrop<T: ?Sized> {
|
|
|
|
pub value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "maybe_uninit"]
|
|
|
|
#[repr(transparent)]
|
2019-07-07 04:59:11 -05:00
|
|
|
pub union MaybeUninit<T> {
|
|
|
|
pub uninit: (),
|
2019-10-25 14:24:50 -05:00
|
|
|
pub value: ManuallyDrop<T>,
|
2019-07-07 04:59:11 -05:00
|
|
|
}
|
|
|
|
|
2018-07-24 07:10:53 -05:00
|
|
|
pub mod intrinsics {
|
|
|
|
extern "rust-intrinsic" {
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2018-09-02 08:22:04 -05:00
|
|
|
pub fn abort() -> !;
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2018-07-24 07:10:53 -05:00
|
|
|
pub fn size_of<T>() -> usize;
|
2020-03-24 07:09:44 -05:00
|
|
|
pub fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2018-09-15 04:14:27 -05:00
|
|
|
pub fn min_align_of<T>() -> usize;
|
2020-03-24 07:09:44 -05:00
|
|
|
pub fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
|
2018-07-24 07:10:53 -05:00
|
|
|
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
2018-07-26 03:48:50 -05:00
|
|
|
pub fn transmute<T, U>(e: T) -> U;
|
2018-08-08 07:39:46 -05:00
|
|
|
pub fn ctlz_nonzero<T>(x: T) -> T;
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2022-06-03 02:28:19 -05:00
|
|
|
pub fn needs_drop<T: ?::Sized>() -> bool;
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2019-02-23 03:41:34 -06:00
|
|
|
pub fn bitreverse<T>(x: T) -> T;
|
2022-10-23 09:22:55 -05:00
|
|
|
#[rustc_safe_intrinsic]
|
2018-11-17 11:52:47 -06:00
|
|
|
pub fn bswap<T>(x: T) -> T;
|
2020-03-18 14:33:29 -05:00
|
|
|
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
|
2018-07-24 07:10:53 -05:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 05:22:16 -05:00
|
|
|
|
2019-01-26 08:10:21 -06:00
|
|
|
pub mod libc {
|
2022-08-24 11:40:58 -05:00
|
|
|
// With the new Universal CRT, msvc has switched to all the printf functions being inline wrapper
|
|
|
|
// functions. legacy_stdio_definitions.lib which provides the printf wrapper functions as normal
|
|
|
|
// symbols to link against.
|
|
|
|
#[cfg_attr(unix, link(name = "c"))]
|
2023-04-29 07:00:43 -05:00
|
|
|
#[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))]
|
2022-08-24 11:40:58 -05:00
|
|
|
extern "C" {
|
|
|
|
pub fn printf(format: *const i8, ...) -> i32;
|
|
|
|
}
|
|
|
|
|
2021-02-01 03:11:46 -06:00
|
|
|
#[cfg_attr(unix, link(name = "c"))]
|
|
|
|
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
|
2019-01-26 08:10:21 -06:00
|
|
|
extern "C" {
|
2020-06-16 04:50:58 -05:00
|
|
|
pub fn puts(s: *const i8) -> i32;
|
2019-01-26 08:10:21 -06:00
|
|
|
pub fn malloc(size: usize) -> *mut u8;
|
2019-02-07 13:45:15 -06:00
|
|
|
pub fn free(ptr: *mut u8);
|
2019-01-26 08:10:21 -06:00
|
|
|
pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
|
|
|
|
pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
|
|
|
|
pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-08 05:22:16 -05:00
|
|
|
#[lang = "index"]
|
|
|
|
pub trait Index<Idx: ?Sized> {
|
|
|
|
type Output: ?Sized;
|
|
|
|
fn index(&self, index: Idx) -> &Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Index<usize> for [T; 3] {
|
|
|
|
type Output = T;
|
|
|
|
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
|
|
&self[index]
|
|
|
|
}
|
|
|
|
}
|
2018-08-25 04:22:48 -05:00
|
|
|
|
|
|
|
impl<T> Index<usize> for [T] {
|
|
|
|
type Output = T;
|
|
|
|
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
|
|
&self[index]
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 11:55:20 -06:00
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
extern "C" {
|
2019-03-01 11:55:20 -06:00
|
|
|
type VaListImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "va_list"]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct VaList<'a>(&'a mut VaListImpl);
|
2019-07-28 02:24:16 -05:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
2023-04-29 07:00:43 -05:00
|
|
|
pub macro stringify($($t:tt)*) {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2019-07-28 02:24:16 -05:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
2023-04-29 07:00:43 -05:00
|
|
|
pub macro file() {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2019-07-28 02:24:16 -05:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
2023-04-29 07:00:43 -05:00
|
|
|
pub macro line() {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2019-08-18 08:30:06 -05:00
|
|
|
|
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
2023-04-29 07:00:43 -05:00
|
|
|
pub macro cfg() {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2019-08-19 08:36:03 -05:00
|
|
|
|
2023-10-09 03:52:46 -05:00
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
|
|
|
pub macro asm() {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
|
|
|
|
2020-07-09 09:55:38 -05:00
|
|
|
#[rustc_builtin_macro]
|
|
|
|
#[rustc_macro_transparency = "semitransparent"]
|
2023-04-29 07:00:43 -05:00
|
|
|
pub macro global_asm() {
|
|
|
|
/* compiler built-in */
|
|
|
|
}
|
2020-07-09 09:55:38 -05:00
|
|
|
|
2019-08-19 08:36:03 -05:00
|
|
|
pub static A_STATIC: u8 = 42;
|
2019-12-05 14:00:57 -06:00
|
|
|
|
|
|
|
#[lang = "panic_location"]
|
|
|
|
struct PanicLocation {
|
|
|
|
file: &'static str,
|
|
|
|
line: u32,
|
|
|
|
column: u32,
|
|
|
|
}
|
2019-10-27 10:55:35 -05:00
|
|
|
|
|
|
|
#[no_mangle]
|
2023-04-29 07:00:43 -05:00
|
|
|
#[cfg(not(all(windows, target_env = "gnu")))]
|
2019-10-27 10:55:35 -05:00
|
|
|
pub fn get_tls() -> u8 {
|
|
|
|
#[thread_local]
|
|
|
|
static A: u8 = 42;
|
|
|
|
|
|
|
|
A
|
|
|
|
}
|