]> git.lizzy.rs Git - rust.git/blob - tests/run/int_overflow.rs
Initial commit
[rust.git] / tests / run / int_overflow.rs
1 // Compiler:
2 //
3 // Run-time:
4 //   stdout: Panicking
5 //   status: signal
6
7 #![allow(unused_attributes)]
8 #![feature(auto_traits, lang_items, no_core, start, intrinsics)]
9
10 #![no_std]
11 #![no_core]
12
13 /*
14  * Core
15  */
16
17 // Because we don't have core yet.
18 #[lang = "sized"]
19 pub trait Sized {}
20
21 #[lang = "copy"]
22 trait Copy {
23 }
24
25 impl Copy for isize {}
26 impl Copy for *mut i32 {}
27 impl Copy for usize {}
28 impl Copy for i32 {}
29 impl Copy for u8 {}
30 impl Copy for i8 {}
31
32 #[lang = "receiver"]
33 trait Receiver {
34 }
35
36 #[lang = "freeze"]
37 pub(crate) unsafe auto trait Freeze {}
38
39 #[lang = "panic_location"]
40 struct PanicLocation {
41     file: &'static str,
42     line: u32,
43     column: u32,
44 }
45
46 mod libc {
47     #[link(name = "c")]
48     extern "C" {
49         pub fn puts(s: *const u8) -> i32;
50         pub fn fflush(stream: *mut i32) -> i32;
51
52         pub static STDOUT: *mut i32;
53     }
54 }
55
56 mod intrinsics {
57     extern "rust-intrinsic" {
58         pub fn abort() -> !;
59     }
60 }
61
62 #[lang = "panic"]
63 #[track_caller]
64 #[no_mangle]
65 pub fn panic(_msg: &str) -> ! {
66     unsafe {
67         libc::puts("Panicking\0" as *const str as *const u8);
68         libc::fflush(libc::STDOUT);
69         intrinsics::abort();
70     }
71 }
72
73 #[lang = "add"]
74 trait Add<RHS = Self> {
75     type Output;
76
77     fn add(self, rhs: RHS) -> Self::Output;
78 }
79
80 impl Add for u8 {
81     type Output = Self;
82
83     fn add(self, rhs: Self) -> Self {
84         self + rhs
85     }
86 }
87
88 impl Add for i8 {
89     type Output = Self;
90
91     fn add(self, rhs: Self) -> Self {
92         self + rhs
93     }
94 }
95
96 impl Add for i32 {
97     type Output = Self;
98
99     fn add(self, rhs: Self) -> Self {
100         self + rhs
101     }
102 }
103
104 impl Add for usize {
105     type Output = Self;
106
107     fn add(self, rhs: Self) -> Self {
108         self + rhs
109     }
110 }
111
112 impl Add for isize {
113     type Output = Self;
114
115     fn add(self, rhs: Self) -> Self {
116         self + rhs
117     }
118 }
119
120 /*
121  * Code
122  */
123
124 #[start]
125 fn main(mut argc: isize, _argv: *const *const u8) -> isize {
126     let int = 9223372036854775807isize;
127     let int = int + argc;
128     int
129 }