@@ -64,17 +64,9 @@ unsafe impl Sync for [u8; 16] {}
64
64
#[ lang = "freeze" ]
65
65
unsafe auto trait Freeze { }
66
66
67
- unsafe impl < T : ?Sized > Freeze for * const T { }
68
- unsafe impl < T : ?Sized > Freeze for * mut T { }
69
- unsafe impl < T : ?Sized > Freeze for & T { }
70
- unsafe impl < T : ?Sized > Freeze for & mut T { }
71
-
72
67
#[ lang = "structural_peq" ]
73
68
pub trait StructuralPartialEq { }
74
69
75
- #[ lang = "structural_teq" ]
76
- pub trait StructuralEq { }
77
-
78
70
#[ lang = "not" ]
79
71
pub trait Not {
80
72
type Output ;
@@ -185,7 +177,7 @@ pub mod intrinsics {
185
177
pub fn min_align_of_val < T : ?:: Sized > ( val : * const T ) -> usize ;
186
178
pub fn copy < T > ( src : * const T , dst : * mut T , count : usize ) ;
187
179
pub fn transmute < T , U > ( e : T ) -> U ;
188
- pub fn ctlz_nonzero < T > ( x : T ) -> T ;
180
+ pub fn ctlz_nonzero < T > ( x : T ) -> u32 ;
189
181
#[ rustc_safe_intrinsic]
190
182
pub fn needs_drop < T : ?:: Sized > ( ) -> bool ;
191
183
#[ rustc_safe_intrinsic]
@@ -274,24 +266,67 @@ extern "C" {
274
266
275
267
#[ lang = "panic" ]
276
268
#[ track_caller]
277
- pub fn panic ( _msg : & ' static str ) -> ! {
278
- let ciovec = Ciovec { buf : "Panicking\n " as * const str as * const u8 , buf_len : 10 } ;
269
+ pub fn panic ( msg : & ' static str ) -> ! {
270
+ let ciovec = Ciovec { buf : "Panicking at " as * const str as * const u8 , buf_len : 13 } ;
279
271
unsafe {
280
272
fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
281
273
}
282
274
let caller = intrinsics:: caller_location ( ) ;
283
275
let ciovec =
284
- Ciovec { buf : caller. file as * const str as * const u8 , buf_len : 22 /* FIXME */ } ;
276
+ Ciovec { buf : caller. file as * const str as * const u8 , buf_len : 24 /* FIXME */ } ;
277
+ unsafe {
278
+ fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
279
+ }
280
+ let ciovec = Ciovec { buf : ": \n " as * const str as * const u8 , buf_len : 3 } ;
281
+ unsafe {
282
+ fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
283
+ }
284
+ let ciovec = Ciovec { buf : msg as * const str as * const u8 , buf_len : 4 /* FIXME */ } ;
285
285
unsafe {
286
286
fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
287
287
}
288
- let ciovec = Ciovec { buf : "\n " as * const str as * const u8 , buf_len : 1 /* FIXME */ } ;
288
+ let ciovec = Ciovec { buf : "\n " as * const str as * const u8 , buf_len : 1 } ;
289
289
unsafe {
290
290
fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
291
291
}
292
292
intrinsics:: abort ( ) ;
293
293
}
294
294
295
+ macro_rules! panic_const {
296
+ ( $( $lang: ident = $message: expr, ) +) => {
297
+ pub mod panic_const {
298
+ use super :: * ;
299
+
300
+ $(
301
+ #[ track_caller]
302
+ #[ lang = stringify!( $lang) ]
303
+ pub fn $lang( ) -> ! {
304
+ panic( $message) ;
305
+ }
306
+ ) +
307
+ }
308
+ }
309
+ }
310
+
311
+ panic_const ! {
312
+ panic_const_add_overflow = "attempt to add with overflow" ,
313
+ panic_const_sub_overflow = "attempt to subtract with overflow" ,
314
+ panic_const_mul_overflow = "attempt to multiply with overflow" ,
315
+ panic_const_div_overflow = "attempt to divide with overflow" ,
316
+ panic_const_rem_overflow = "attempt to calculate the remainder with overflow" ,
317
+ panic_const_neg_overflow = "attempt to negate with overflow" ,
318
+ panic_const_shr_overflow = "attempt to shift right with overflow" ,
319
+ panic_const_shl_overflow = "attempt to shift left with overflow" ,
320
+ panic_const_div_by_zero = "attempt to divide by zero" ,
321
+ panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero" ,
322
+ }
323
+
324
+ #[ rustc_builtin_macro]
325
+ #[ rustc_macro_transparency = "semitransparent" ]
326
+ pub macro stringify( $( $t: tt) * ) {
327
+ /* compiler built-in */
328
+ }
329
+
295
330
#[ lang = "panic_location" ]
296
331
struct Location < ' a > {
297
332
file : & ' a str ,
@@ -300,7 +335,7 @@ struct Location<'a> {
300
335
}
301
336
302
337
#[ no_mangle]
303
- fn main ( foo : u32 ) -> u32 {
338
+ fn _start ( ) {
304
339
let ciovec = Ciovec { buf : "foo\n " as * const str as * const u8 , buf_len : 4 } ;
305
340
unsafe {
306
341
fd_write ( 2 , & ciovec, 1 , & mut 0 ) ;
@@ -318,10 +353,12 @@ fn main(foo: u32) -> u32 {
318
353
}
319
354
320
355
if argc != 2 {
321
- intrinsics:: abort ( ) ;
356
+ // intrinsics::abort();
322
357
}
323
358
324
- add_1 ( foo) + add_1_and_2 ( foo) . 1 + argc
359
+ if add_1 ( argc) + add_1_and_2 ( argc) . 1 + argc != 9 {
360
+ panic ( "oops" ) ;
361
+ }
325
362
}
326
363
327
364
fn add_1 ( foo : u32 ) -> u32 {
0 commit comments