2019-03-01 17:55:20 +00:00
|
|
|
#![feature(no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types)]
|
2018-07-24 12:10:53 +00:00
|
|
|
#![no_core]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2018-07-31 10:25:16 +00:00
|
|
|
#[lang = "sized"]
|
2018-07-24 12:10:53 +00:00
|
|
|
pub trait Sized {}
|
|
|
|
|
2018-07-30 15:29:39 +00:00
|
|
|
#[lang = "unsize"]
|
|
|
|
pub trait Unsize<T: ?Sized> {}
|
|
|
|
|
|
|
|
#[lang = "coerce_unsized"]
|
|
|
|
pub trait CoerceUnsized<T> {}
|
|
|
|
|
2018-07-31 10:25:16 +00:00
|
|
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
2018-12-29 14:33:34 +00:00
|
|
|
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
|
2018-09-16 12:49:45 +00:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
2018-09-16 09:57:27 +00:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
2018-07-30 15:29:39 +00:00
|
|
|
|
2018-11-03 17:22:05 +00:00
|
|
|
#[lang = "dispatch_from_dyn"]
|
|
|
|
pub trait DispatchFromDyn<T> {}
|
|
|
|
|
|
|
|
// &T -> &U
|
|
|
|
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
|
|
|
|
// &mut T -> &mut U
|
|
|
|
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
|
|
|
|
// *const T -> *const U
|
|
|
|
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
|
|
|
|
// *mut T -> *mut U
|
|
|
|
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
|
2019-03-02 20:09:28 +00:00
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
|
2018-11-03 17:22:05 +00:00
|
|
|
|
2018-12-24 13:50:18 +00: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 10:25:16 +00:00
|
|
|
#[lang = "copy"]
|
2018-07-24 12:10:53 +00:00
|
|
|
pub unsafe trait Copy {}
|
|
|
|
|
2018-07-26 08:59:57 +00:00
|
|
|
unsafe impl Copy for bool {}
|
2018-07-24 12:10:53 +00:00
|
|
|
unsafe impl Copy for u8 {}
|
|
|
|
unsafe impl Copy for u16 {}
|
|
|
|
unsafe impl Copy for u32 {}
|
|
|
|
unsafe impl Copy for u64 {}
|
|
|
|
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 {}
|
2018-07-26 08:48:50 +00:00
|
|
|
unsafe impl Copy for char {}
|
2018-07-24 12:10:53 +00:00
|
|
|
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
|
|
|
|
unsafe impl<T: ?Sized> Copy for *const T {}
|
2019-01-26 14:10:21 +00:00
|
|
|
unsafe impl<T: ?Sized> Copy for *mut T {}
|
2018-07-24 12:10:53 +00:00
|
|
|
|
2018-08-09 09:41:34 +00: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 {}
|
2018-08-13 17:02:42 +00:00
|
|
|
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
|
2018-09-04 17:04:25 +00:00
|
|
|
unsafe impl Sync for [u8; 16] {}
|
2018-08-09 09:41:34 +00:00
|
|
|
|
2018-07-31 10:25:16 +00:00
|
|
|
#[lang = "freeze"]
|
2018-07-24 12:10:53 +00:00
|
|
|
trait Freeze {}
|
|
|
|
|
2018-09-14 17:49:33 +00: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 10:25:16 +00:00
|
|
|
#[lang = "mul"]
|
2018-07-24 12:10:53 +00: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 13:56:01 +00:00
|
|
|
fn mul(self, rhs: Self) -> Self::Output {
|
2018-07-24 12:10:53 +00:00
|
|
|
self * rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 17:53:18 +00:00
|
|
|
impl Mul for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn mul(self, rhs: Self) -> Self::Output {
|
|
|
|
self * rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:14:55 +00: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-01-26 14:10:21 +00:00
|
|
|
impl Add for usize {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, rhs: Self) -> Self {
|
|
|
|
self + rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:56:01 +00: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 10:25:16 +00:00
|
|
|
#[lang = "bitor"]
|
2018-07-26 08:59:57 +00: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 12:10:53 +00: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 10:25:16 +00:00
|
|
|
fn eq(&self, other: &u8) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &u8) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
2018-07-24 12:10:53 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 14:10:21 +00: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for usize {
|
|
|
|
fn eq(&self, other: &usize) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &usize) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 20:09:28 +00:00
|
|
|
impl PartialEq for i32 {
|
|
|
|
fn eq(&self, other: &i32) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &i32) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 17:53:18 +00:00
|
|
|
impl PartialEq for isize {
|
|
|
|
fn eq(&self, other: &isize) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &isize) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 08:48:50 +00:00
|
|
|
impl PartialEq for char {
|
2018-07-31 10:25:16 +00:00
|
|
|
fn eq(&self, other: &char) -> bool {
|
|
|
|
(*self) == (*other)
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &char) -> bool {
|
|
|
|
(*self) != (*other)
|
|
|
|
}
|
2018-07-26 08:48:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 12:10:53 +00:00
|
|
|
impl<T: ?Sized> PartialEq for *const T {
|
2018-07-31 10:25:16 +00:00
|
|
|
fn eq(&self, other: &*const T) -> bool {
|
|
|
|
*self == *other
|
|
|
|
}
|
|
|
|
fn ne(&self, other: &*const T) -> bool {
|
|
|
|
*self != *other
|
|
|
|
}
|
2018-07-24 12:10:53 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 16:02:37 +00:00
|
|
|
#[lang = "neg"]
|
|
|
|
pub trait Neg {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn neg(self) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Neg for isize {
|
|
|
|
type Output = isize;
|
|
|
|
|
|
|
|
fn neg(self) -> isize {
|
|
|
|
-self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 14:21:07 +00:00
|
|
|
pub enum Option<T> {
|
|
|
|
Some(T),
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use Option::*;
|
|
|
|
|
2018-09-16 12:49:45 +00:00
|
|
|
#[lang = "phantom_data"]
|
|
|
|
pub struct PhantomData<T: ?Sized>;
|
|
|
|
|
2018-07-20 11:38:49 +00:00
|
|
|
#[lang = "fn_once"]
|
|
|
|
#[rustc_paren_sugar]
|
2018-07-27 17:27:20 +00:00
|
|
|
pub trait FnOnce<Args> {
|
2018-07-20 11:38:49 +00:00
|
|
|
type Output;
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "fn_mut"]
|
|
|
|
#[rustc_paren_sugar]
|
2018-07-31 10:25:16 +00:00
|
|
|
pub trait FnMut<Args>: FnOnce<Args> {
|
2018-07-20 11:38:49 +00:00
|
|
|
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
2018-07-31 10:25:16 +00:00
|
|
|
#[lang = "panic"]
|
2019-01-26 14:16:58 +00:00
|
|
|
// Make it available to jited mini_core_hello_world
|
|
|
|
// FIXME remove next line when jit supports linking rlibs
|
|
|
|
#[inline(always)]
|
2019-01-26 14:10:21 +00:00
|
|
|
pub fn panic(&(_msg, _file, _line, _col): &(&'static str, &'static str, u32, u32)) -> ! {
|
2018-09-02 13:22:04 +00:00
|
|
|
unsafe {
|
2019-01-26 14:14:39 +00:00
|
|
|
libc::puts("Panicking\0" as *const str as *const u8);
|
2018-09-02 13:22:04 +00:00
|
|
|
intrinsics::abort();
|
|
|
|
}
|
2018-07-24 12:10:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-11 12:52:00 +00:00
|
|
|
#[lang = "eh_personality"]
|
|
|
|
fn eh_personality() -> ! {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2018-07-24 12:10:53 +00: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);
|
|
|
|
}
|
|
|
|
|
2019-03-02 20:09:28 +00:00
|
|
|
#[lang = "deref"]
|
|
|
|
pub trait Deref {
|
|
|
|
type Target: ?Sized;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target;
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:04:25 +00:00
|
|
|
#[lang = "owned_box"]
|
2018-09-16 09:57:27 +00:00
|
|
|
pub struct Box<T: ?Sized>(*mut T);
|
|
|
|
|
|
|
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
|
2018-09-04 17:04:25 +00:00
|
|
|
|
2019-02-07 19:45:15 +00:00
|
|
|
impl<T: ?Sized> Drop for Box<T> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
// drop is currently performed by compiler.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 20:09:28 +00:00
|
|
|
impl<T> Deref for Box<T> {
|
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&**self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:04:25 +00:00
|
|
|
#[lang = "exchange_malloc"]
|
2019-01-26 14:10:21 +00:00
|
|
|
// Make it available to jited mini_core_hello_world
|
|
|
|
// FIXME remove next line when jit supports linking rlibs
|
|
|
|
#[inline(always)]
|
2018-09-04 17:04:25 +00:00
|
|
|
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
2019-01-26 14:10:21 +00:00
|
|
|
libc::malloc(size)
|
2018-09-04 17:04:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 19:45:15 +00:00
|
|
|
#[lang = "box_free"]
|
|
|
|
#[inline(always)]
|
|
|
|
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
|
|
|
|
libc::free(ptr as *mut u8);
|
|
|
|
}
|
|
|
|
|
2018-09-11 17:27:57 +00:00
|
|
|
#[lang = "drop"]
|
|
|
|
pub trait Drop {
|
|
|
|
fn drop(&mut self);
|
|
|
|
}
|
|
|
|
|
2018-07-24 12:10:53 +00:00
|
|
|
pub mod intrinsics {
|
|
|
|
extern "rust-intrinsic" {
|
2018-09-02 13:22:04 +00:00
|
|
|
pub fn abort() -> !;
|
2018-07-24 12:10:53 +00:00
|
|
|
pub fn size_of<T>() -> usize;
|
2018-09-06 16:45:29 +00:00
|
|
|
pub fn size_of_val<T: ?::Sized>(val: &T) -> usize;
|
2018-09-15 09:14:27 +00:00
|
|
|
pub fn min_align_of<T>() -> usize;
|
|
|
|
pub fn min_align_of_val<T: ?::Sized>(val: &T) -> usize;
|
2018-07-24 12:10:53 +00:00
|
|
|
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
2018-07-26 08:48:50 +00:00
|
|
|
pub fn transmute<T, U>(e: T) -> U;
|
2018-07-29 15:22:40 +00:00
|
|
|
pub fn uninit<T>() -> T;
|
2019-02-24 15:46:11 +00:00
|
|
|
pub fn init<T>() -> T;
|
2018-08-08 12:39:46 +00:00
|
|
|
pub fn ctlz_nonzero<T>(x: T) -> T;
|
2018-09-14 17:49:33 +00:00
|
|
|
pub fn needs_drop<T>() -> bool;
|
2019-02-23 09:41:34 +00:00
|
|
|
pub fn bitreverse<T>(x: T) -> T;
|
2018-07-24 12:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 10:22:16 +00:00
|
|
|
|
2019-01-26 14:10:21 +00:00
|
|
|
pub mod libc {
|
|
|
|
#[link(name = "c")]
|
|
|
|
extern "C" {
|
|
|
|
pub fn puts(s: *const u8);
|
2019-02-12 07:24:32 +00:00
|
|
|
pub fn printf(format: *const i8, ...) -> i32;
|
2019-01-26 14:10:21 +00:00
|
|
|
pub fn malloc(size: usize) -> *mut u8;
|
2019-02-07 19:45:15 +00:00
|
|
|
pub fn free(ptr: *mut u8);
|
2019-01-26 14:10:21 +00: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 10:22:16 +00: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 09:22:48 +00:00
|
|
|
|
|
|
|
impl<T> Index<usize> for [T] {
|
|
|
|
type Output = T;
|
|
|
|
|
|
|
|
fn index(&self, index: usize) -> &Self::Output {
|
|
|
|
&self[index]
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 17:55:20 +00:00
|
|
|
|
|
|
|
extern {
|
|
|
|
type VaListImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[lang = "va_list"]
|
|
|
|
#[repr(transparent)]
|
|
|
|
pub struct VaList<'a>(&'a mut VaListImpl);
|