11 #![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics,
21 // Because we don't have core yet.
29 impl Copy for isize {}
30 impl Copy for usize {}
41 pub(crate) unsafe auto trait Freeze {}
46 pub fn puts(s: *const u8) -> i32;
47 pub fn printf(format: *const i8, ...) -> i32;
52 pub trait Index<Idx: ?Sized> {
54 fn index(&self, index: Idx) -> &Self::Output;
57 impl<T> Index<usize> for [T; 3] {
60 fn index(&self, index: usize) -> &Self::Output {
65 impl<T> Index<usize> for [T] {
68 fn index(&self, index: usize) -> &Self::Output {
73 #[lang = "drop_in_place"]
74 #[allow(unconditional_recursion)]
75 pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
76 // Code here does not matter - this is replaced by the
77 // real drop glue by the compiler.
78 drop_in_place(to_drop);
81 #[lang = "panic_location"]
82 struct PanicLocation {
88 #[lang = "panic_bounds_check"]
91 fn panic_bounds_check(index: usize, len: usize) -> ! {
93 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);
99 extern "rust-intrinsic" {
105 pub trait Unsize<T: ?Sized> {}
107 #[lang = "coerce_unsized"]
108 pub trait CoerceUnsized<T> {}
110 impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
111 impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
112 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
113 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
117 pub trait FnOnce<Args> {
118 #[lang = "fn_once_output"]
121 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
126 pub trait FnMut<Args>: FnOnce<Args> {
127 extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
131 trait Add<RHS = Self> {
134 fn add(self, rhs: RHS) -> Self::Output;
140 fn add(self, rhs: Self) -> Self {
148 fn add(self, rhs: Self) -> Self {
156 fn add(self, rhs: Self) -> Self {
164 fn add(self, rhs: Self) -> Self {
172 fn add(self, rhs: Self) -> Self {
180 pub fn panic(_msg: &str) -> ! {
182 libc::puts("Panicking\0" as *const str as *const u8);
192 fn main(mut argc: isize, _argv: *const *const u8) -> isize {
193 let string = "Arg: %d\n\0";
194 let mut closure = || {
196 libc::printf(string as *const str as *const i8, argc);
201 let mut closure = || {
203 libc::printf("Argument: %d\n\0" as *const str as *const i8, argc);
208 let mut closure = |string| {
210 libc::printf(string as *const str as *const i8, argc);
213 closure("String arg: %d\n\0");
215 let mut closure = |arg: isize| {
217 libc::printf("Int argument: %d\n\0" as *const str as *const i8, arg);
222 let mut closure = |string, arg: isize| {
224 libc::printf(string as *const str as *const i8, arg);
227 closure("Both args: %d\n\0", argc + 10);