From 30185d09f627e15effbb346bcacf06a37c7299e7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 15 Jul 2018 11:21:56 +0200 Subject: [PATCH] make sure we show error messages even when we cannot show span --- src/lib.rs | 6 ++++-- tests/compile-fail-fullmir/reallocate-change-alloc.rs | 2 +- tests/compile-fail/alignment.rs | 2 +- tests/compile-fail/assume.rs | 2 +- tests/compile-fail/bitop-beyond-alignment.rs | 2 +- tests/compile-fail/cast_box_int_to_fn_ptr.rs | 2 +- tests/compile-fail/cast_fn_ptr.rs | 2 +- tests/compile-fail/cast_fn_ptr2.rs | 2 +- tests/compile-fail/cast_int_to_fn_ptr.rs | 2 +- tests/compile-fail/ctlz_nonzero.rs | 2 +- tests/compile-fail/cttz_nonzero.rs | 2 +- tests/compile-fail/dangling_pointer_deref.rs | 2 +- tests/compile-fail/deref_fn_ptr.rs | 2 +- tests/compile-fail/div-by-zero-2.rs | 2 +- tests/compile-fail/execute_memory.rs | 2 +- tests/compile-fail/fn_ptr_offset.rs | 2 +- tests/compile-fail/invalid_bool.rs | 2 +- tests/compile-fail/invalid_enum_discriminant.rs | 2 +- tests/compile-fail/match_char.rs | 2 +- tests/compile-fail/modifying_constants.rs | 2 +- tests/compile-fail/never_say_never.rs | 2 +- tests/compile-fail/never_transmute_humans.rs | 2 +- tests/compile-fail/never_transmute_void.rs | 2 +- tests/compile-fail/null_pointer_deref.rs | 2 +- tests/compile-fail/out_of_bounds_read.rs | 2 +- tests/compile-fail/out_of_bounds_read2.rs | 2 +- tests/compile-fail/overflowing-lsh-neg.rs | 2 +- tests/compile-fail/overflowing-rsh-2.rs | 2 +- tests/compile-fail/overflowing-rsh.rs | 2 +- ...erwriting_part_of_relocation_makes_the_rest_undefined.rs | 2 +- tests/compile-fail/pointer_byte_read_1.rs | 2 +- tests/compile-fail/pointer_byte_read_2.rs | 2 +- .../pointers_to_different_allocations_are_unorderable.rs | 2 +- tests/compile-fail/ptr_bitops.rs | 2 +- tests/compile-fail/ptr_int_cast.rs | 2 +- tests/compile-fail/reading_half_a_pointer.rs | 2 +- tests/compile-fail/reference_to_packed.rs | 2 +- tests/compile-fail/static_memory_modification.rs | 2 +- tests/compile-fail/static_memory_modification2.rs | 2 +- tests/compile-fail/static_memory_modification3.rs | 2 +- tests/compile-fail/transmute-pair-undef.rs | 2 +- tests/compile-fail/transmute_fat.rs | 2 +- tests/compile-fail/transmute_fat2.rs | 2 +- tests/compile-fail/unaligned_ptr_cast.rs | 2 +- tests/compile-fail/unaligned_ptr_cast2.rs | 2 +- tests/compile-fail/unaligned_ptr_cast_zst.rs | 2 +- tests/compile-fail/wild_pointer_deref.rs | 2 +- tests/compile-fail/zst.rs | 2 +- 48 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 75397262b225..520d696405a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -274,9 +274,11 @@ pub fn eval_main<'a, 'tcx: 'a>( block.terminator().source_info.span }; - let mut err = struct_error(ecx.tcx.tcx.at(span), "constant evaluation error"); + let e = e.to_string(); + let msg = format!("constant evaluation error: {}", e); + let mut err = struct_error(ecx.tcx.tcx.at(span), msg.as_str()); let (frames, span) = ecx.generate_stacktrace(None); - err.span_label(span, e.to_string()); + err.span_label(span, e); for FrameInfo { span, location, .. } in frames { err.span_note(span, &format!("inside call to `{}`", location)); } diff --git a/tests/compile-fail-fullmir/reallocate-change-alloc.rs b/tests/compile-fail-fullmir/reallocate-change-alloc.rs index 03040cd178da..a44ccf4c49cd 100644 --- a/tests/compile-fail-fullmir/reallocate-change-alloc.rs +++ b/tests/compile-fail-fullmir/reallocate-change-alloc.rs @@ -9,7 +9,7 @@ fn main() { unsafe { let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); let _y = Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap(); - let _z = *(x.as_ptr() as *mut u8); //~ ERROR constant evaluation error [E0080] + let _z = *(x.as_ptr() as *mut u8); //~ ERROR constant evaluation error //~^ NOTE dangling pointer was dereferenced } } diff --git a/tests/compile-fail/alignment.rs b/tests/compile-fail/alignment.rs index 9730fe473aa5..71161f5d6da0 100644 --- a/tests/compile-fail/alignment.rs +++ b/tests/compile-fail/alignment.rs @@ -5,7 +5,7 @@ fn main() { let x_ptr: *mut u8 = &mut x[0]; let y_ptr = x_ptr as *mut u64; unsafe { - *y_ptr = 42; //~ ERROR constant evaluation error [E0080] + *y_ptr = 42; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 1, but alignment } panic!("unreachable in miri"); diff --git a/tests/compile-fail/assume.rs b/tests/compile-fail/assume.rs index cf0632393ad6..d9eec480cd0c 100644 --- a/tests/compile-fail/assume.rs +++ b/tests/compile-fail/assume.rs @@ -5,7 +5,7 @@ fn main() { unsafe { std::intrinsics::assume(x < 10); std::intrinsics::assume(x > 1); - std::intrinsics::assume(x > 42); //~ ERROR constant evaluation error [E0080] + std::intrinsics::assume(x > 42); //~ ERROR constant evaluation error //~^ NOTE `assume` argument was false } } diff --git a/tests/compile-fail/bitop-beyond-alignment.rs b/tests/compile-fail/bitop-beyond-alignment.rs index 89f5e048a36d..c8cbc9a91841 100644 --- a/tests/compile-fail/bitop-beyond-alignment.rs +++ b/tests/compile-fail/bitop-beyond-alignment.rs @@ -28,7 +28,7 @@ fn mk_rec() -> Rec { fn is_u64_aligned(u: &Tag) -> bool { let p: usize = unsafe { mem::transmute(u) }; let u64_align = std::mem::align_of::(); - return (p & (u64_align + 1)) == 0; //~ ERROR constant evaluation error [E0080] + return (p & (u64_align + 1)) == 0; //~ ERROR constant evaluation error //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes } diff --git a/tests/compile-fail/cast_box_int_to_fn_ptr.rs b/tests/compile-fail/cast_box_int_to_fn_ptr.rs index 39b53da0b75c..2a317f579f5e 100644 --- a/tests/compile-fail/cast_box_int_to_fn_ptr.rs +++ b/tests/compile-fail/cast_box_int_to_fn_ptr.rs @@ -7,6 +7,6 @@ fn main() { std::mem::transmute::<&usize, &fn(i32)>(&b) }; - (*g)(42) //~ ERROR constant evaluation error [E0080] + (*g)(42) //~ ERROR constant evaluation error //~^ NOTE a memory access tried to interpret some bytes as a pointer } diff --git a/tests/compile-fail/cast_fn_ptr.rs b/tests/compile-fail/cast_fn_ptr.rs index 19344b13ba7c..0a8f5ef752a6 100644 --- a/tests/compile-fail/cast_fn_ptr.rs +++ b/tests/compile-fail/cast_fn_ptr.rs @@ -5,6 +5,6 @@ fn main() { std::mem::transmute::(f) }; - g(42) //~ ERROR constant evaluation error [E0080] + g(42) //~ ERROR constant evaluation error //~^ NOTE tried to call a function with sig fn() through a function pointer of type fn(i32) } diff --git a/tests/compile-fail/cast_fn_ptr2.rs b/tests/compile-fail/cast_fn_ptr2.rs index 23868c0e57db..cb80521c60ee 100644 --- a/tests/compile-fail/cast_fn_ptr2.rs +++ b/tests/compile-fail/cast_fn_ptr2.rs @@ -5,6 +5,6 @@ fn main() { std::mem::transmute::(f) }; - g(42) //~ ERROR constant evaluation error [E0080] + g(42) //~ ERROR constant evaluation error //~^ NOTE tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32) } diff --git a/tests/compile-fail/cast_int_to_fn_ptr.rs b/tests/compile-fail/cast_int_to_fn_ptr.rs index c7556ae06b93..29d16e9a4259 100644 --- a/tests/compile-fail/cast_int_to_fn_ptr.rs +++ b/tests/compile-fail/cast_int_to_fn_ptr.rs @@ -6,6 +6,6 @@ fn main() { std::mem::transmute::(42) }; - g(42) //~ ERROR constant evaluation error [E0080] + g(42) //~ ERROR constant evaluation error //~^ NOTE a memory access tried to interpret some bytes as a pointer } diff --git a/tests/compile-fail/ctlz_nonzero.rs b/tests/compile-fail/ctlz_nonzero.rs index d952187eba45..167100903f4d 100644 --- a/tests/compile-fail/ctlz_nonzero.rs +++ b/tests/compile-fail/ctlz_nonzero.rs @@ -10,7 +10,7 @@ pub fn main() { unsafe { use rusti::*; - ctlz_nonzero(0u8); //~ ERROR constant evaluation error [E0080] + ctlz_nonzero(0u8); //~ ERROR constant evaluation error //~^ NOTE ctlz_nonzero called on 0 } } diff --git a/tests/compile-fail/cttz_nonzero.rs b/tests/compile-fail/cttz_nonzero.rs index b308484622bc..7d9ac5a0212d 100644 --- a/tests/compile-fail/cttz_nonzero.rs +++ b/tests/compile-fail/cttz_nonzero.rs @@ -10,7 +10,7 @@ pub fn main() { unsafe { use rusti::*; - cttz_nonzero(0u8); //~ ERROR constant evaluation error [E0080] + cttz_nonzero(0u8); //~ ERROR constant evaluation error //~^ NOTE cttz_nonzero called on 0 } } diff --git a/tests/compile-fail/dangling_pointer_deref.rs b/tests/compile-fail/dangling_pointer_deref.rs index d42c1d33b530..434f5c780b46 100644 --- a/tests/compile-fail/dangling_pointer_deref.rs +++ b/tests/compile-fail/dangling_pointer_deref.rs @@ -3,7 +3,7 @@ fn main() { let b = Box::new(42); &*b as *const i32 }; - let x = unsafe { *p }; //~ ERROR constant evaluation error [E0080] + let x = unsafe { *p }; //~ ERROR constant evaluation error //~^ NOTE dangling pointer was dereferenced panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/deref_fn_ptr.rs b/tests/compile-fail/deref_fn_ptr.rs index a56df5bce408..fb3aea67e821 100644 --- a/tests/compile-fail/deref_fn_ptr.rs +++ b/tests/compile-fail/deref_fn_ptr.rs @@ -2,7 +2,7 @@ fn f() {} fn main() { let x: i32 = unsafe { - *std::mem::transmute::(f) //~ ERROR constant evaluation error [E0080] + *std::mem::transmute::(f) //~ ERROR constant evaluation error //~^ NOTE tried to dereference a function pointer }; panic!("this should never print: {}", x); diff --git a/tests/compile-fail/div-by-zero-2.rs b/tests/compile-fail/div-by-zero-2.rs index c90ca8d15cce..94145c2cf32f 100644 --- a/tests/compile-fail/div-by-zero-2.rs +++ b/tests/compile-fail/div-by-zero-2.rs @@ -11,6 +11,6 @@ #![allow(const_err)] fn main() { - let _n = 1 / 0; //~ ERROR constant evaluation error [E0080] + let _n = 1 / 0; //~ ERROR constant evaluation error //~^ NOTE attempt to divide by zero } diff --git a/tests/compile-fail/execute_memory.rs b/tests/compile-fail/execute_memory.rs index 014c551df0f1..bcde13d13ee7 100644 --- a/tests/compile-fail/execute_memory.rs +++ b/tests/compile-fail/execute_memory.rs @@ -7,7 +7,7 @@ fn main() { let x = box 42; unsafe { let f = std::mem::transmute::, fn()>(x); - f() //~ ERROR constant evaluation error [E0080] + f() //~ ERROR constant evaluation error //~^ NOTE tried to treat a memory pointer as a function pointer } } diff --git a/tests/compile-fail/fn_ptr_offset.rs b/tests/compile-fail/fn_ptr_offset.rs index 20eb6573989c..0c0590e375bb 100644 --- a/tests/compile-fail/fn_ptr_offset.rs +++ b/tests/compile-fail/fn_ptr_offset.rs @@ -10,6 +10,6 @@ fn main() { let y : *mut u8 = unsafe { mem::transmute(x) }; let y = y.wrapping_offset(1); let x : fn() = unsafe { mem::transmute(y) }; - x(); //~ ERROR constant evaluation error [E0080] + x(); //~ ERROR constant evaluation error //~^ NOTE tried to use a function pointer after offsetting it } diff --git a/tests/compile-fail/invalid_bool.rs b/tests/compile-fail/invalid_bool.rs index 07c407966a8f..1aa5d9bf77bc 100644 --- a/tests/compile-fail/invalid_bool.rs +++ b/tests/compile-fail/invalid_bool.rs @@ -1,5 +1,5 @@ fn main() { let b = unsafe { std::mem::transmute::(2) }; - if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error [E0080] + if b { unreachable!() } else { unreachable!() } //~ ERROR constant evaluation error //~^ NOTE invalid boolean value read } diff --git a/tests/compile-fail/invalid_enum_discriminant.rs b/tests/compile-fail/invalid_enum_discriminant.rs index 69d7e3e427d4..760b6563d27c 100644 --- a/tests/compile-fail/invalid_enum_discriminant.rs +++ b/tests/compile-fail/invalid_enum_discriminant.rs @@ -14,5 +14,5 @@ fn main() { Foo::C => {}, Foo::D => {}, } -} //~ ERROR constant evaluation error [E0080] +} //~ ERROR constant evaluation error //~^ NOTE entered unreachable code diff --git a/tests/compile-fail/match_char.rs b/tests/compile-fail/match_char.rs index 0d45d70eb781..52f33b58e6fb 100644 --- a/tests/compile-fail/match_char.rs +++ b/tests/compile-fail/match_char.rs @@ -2,7 +2,7 @@ fn main() { assert!(std::char::from_u32(-1_i32 as u32).is_none()); - match unsafe { std::mem::transmute::(-1) } { //~ ERROR constant evaluation error [E0080] + match unsafe { std::mem::transmute::(-1) } { //~ ERROR constant evaluation error //~^ NOTE tried to interpret an invalid 32-bit value as a char: 4294967295 'a' => {}, 'b' => {}, diff --git a/tests/compile-fail/modifying_constants.rs b/tests/compile-fail/modifying_constants.rs index 06920fa0acf1..c10657ae75a7 100644 --- a/tests/compile-fail/modifying_constants.rs +++ b/tests/compile-fail/modifying_constants.rs @@ -1,7 +1,7 @@ fn main() { let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee let y = unsafe { &mut *(x as *const i32 as *mut i32) }; - *y = 42; //~ ERROR constant evaluation error [E0080] + *y = 42; //~ ERROR constant evaluation error //~^ NOTE tried to modify constant memory assert_eq!(*x, 42); } diff --git a/tests/compile-fail/never_say_never.rs b/tests/compile-fail/never_say_never.rs index de8815ffd9c4..fd76ecbd1503 100644 --- a/tests/compile-fail/never_say_never.rs +++ b/tests/compile-fail/never_say_never.rs @@ -7,7 +7,7 @@ fn main() { let y = &5; let x: ! = unsafe { - *(y as *const _ as *const !) //~ ERROR constant evaluation error [E0080] + *(y as *const _ as *const !) //~ ERROR constant evaluation error //~^ NOTE entered unreachable code }; f(x) diff --git a/tests/compile-fail/never_transmute_humans.rs b/tests/compile-fail/never_transmute_humans.rs index 3422d52f9c04..7652cdfdd3df 100644 --- a/tests/compile-fail/never_transmute_humans.rs +++ b/tests/compile-fail/never_transmute_humans.rs @@ -9,7 +9,7 @@ struct Human; fn main() { let x: ! = unsafe { - std::mem::transmute::(Human) //~ ERROR constant evaluation error [E0080] + std::mem::transmute::(Human) //~ ERROR constant evaluation error //^~ NOTE entered unreachable code }; f(x) diff --git a/tests/compile-fail/never_transmute_void.rs b/tests/compile-fail/never_transmute_void.rs index 4f1499483eda..9329cd365994 100644 --- a/tests/compile-fail/never_transmute_void.rs +++ b/tests/compile-fail/never_transmute_void.rs @@ -8,7 +8,7 @@ enum Void {} fn f(v: Void) -> ! { - match v {} //~ ERROR constant evaluation error [E0080] + match v {} //~ ERROR constant evaluation error //~^ NOTE entered unreachable code } diff --git a/tests/compile-fail/null_pointer_deref.rs b/tests/compile-fail/null_pointer_deref.rs index 70df937c4c7c..f69308296bc2 100644 --- a/tests/compile-fail/null_pointer_deref.rs +++ b/tests/compile-fail/null_pointer_deref.rs @@ -1,5 +1,5 @@ fn main() { - let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error [E0080] + let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error //~^ NOTE invalid use of NULL pointer panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/out_of_bounds_read.rs b/tests/compile-fail/out_of_bounds_read.rs index d8811e7abcd2..3ccdb365feeb 100644 --- a/tests/compile-fail/out_of_bounds_read.rs +++ b/tests/compile-fail/out_of_bounds_read.rs @@ -1,6 +1,6 @@ fn main() { let v: Vec = vec![1, 2]; - let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error [E0080] + let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error //~^ NOTE which has size 2 panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/out_of_bounds_read2.rs b/tests/compile-fail/out_of_bounds_read2.rs index 54738cf81fbd..811ba7d4b26c 100644 --- a/tests/compile-fail/out_of_bounds_read2.rs +++ b/tests/compile-fail/out_of_bounds_read2.rs @@ -1,6 +1,6 @@ fn main() { let v: Vec = vec![1, 2]; - let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error [E0080] + let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error //~^ NOTE memory access at offset 6, outside bounds of allocation panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/overflowing-lsh-neg.rs b/tests/compile-fail/overflowing-lsh-neg.rs index e50e42503649..825a82226634 100644 --- a/tests/compile-fail/overflowing-lsh-neg.rs +++ b/tests/compile-fail/overflowing-lsh-neg.rs @@ -12,6 +12,6 @@ #![allow(const_err)] fn main() { - let _n = 2i64 << -1; //~ ERROR constant evaluation error [E0080] + let _n = 2i64 << -1; //~ ERROR constant evaluation error //~^ NOTE attempt to shift left with overflow } diff --git a/tests/compile-fail/overflowing-rsh-2.rs b/tests/compile-fail/overflowing-rsh-2.rs index 967c8b020cca..cf107a76ae29 100644 --- a/tests/compile-fail/overflowing-rsh-2.rs +++ b/tests/compile-fail/overflowing-rsh-2.rs @@ -12,6 +12,6 @@ fn main() { // Make sure we catch overflows that would be hidden by first casting the RHS to u32 - let _n = 1i64 >> (u32::max_value() as i64 + 1); //~ ERROR constant evaluation error [E0080] + let _n = 1i64 >> (u32::max_value() as i64 + 1); //~ ERROR constant evaluation error //~^ NOTE attempt to shift right with overflow } diff --git a/tests/compile-fail/overflowing-rsh.rs b/tests/compile-fail/overflowing-rsh.rs index c291815e2e79..ea53d7e73092 100644 --- a/tests/compile-fail/overflowing-rsh.rs +++ b/tests/compile-fail/overflowing-rsh.rs @@ -11,6 +11,6 @@ #![allow(exceeding_bitshifts)] fn main() { - let _n = 1i64 >> 64; //~ ERROR constant evaluation error [E0080] + let _n = 1i64 >> 64; //~ ERROR constant evaluation error //~^ NOTE attempt to shift right with overflow } diff --git a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs b/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs index fabbef5004d7..7c38c0574698 100644 --- a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs +++ b/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs @@ -6,7 +6,7 @@ fn main() { // "attempted to interpret some raw bytes as a pointer address" instead of // "attempted to read undefined bytes" } - let x = *p; //~ ERROR constant evaluation error [E0080] + let x = *p; //~ ERROR constant evaluation error //~^ NOTE attempted to read undefined bytes panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/pointer_byte_read_1.rs b/tests/compile-fail/pointer_byte_read_1.rs index 012af897e837..b3aaec759ce0 100644 --- a/tests/compile-fail/pointer_byte_read_1.rs +++ b/tests/compile-fail/pointer_byte_read_1.rs @@ -3,6 +3,6 @@ fn main() { let y = &x; let z = &y as *const &i32 as *const usize; let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once - let _ = ptr_bytes % 432; //~ ERROR constant evaluation error [E0080] + let _ = ptr_bytes % 432; //~ ERROR constant evaluation error //~^ NOTE tried to access part of a pointer value as raw bytes } diff --git a/tests/compile-fail/pointer_byte_read_2.rs b/tests/compile-fail/pointer_byte_read_2.rs index 4d25a36a3c88..c8a1a2e10f50 100644 --- a/tests/compile-fail/pointer_byte_read_2.rs +++ b/tests/compile-fail/pointer_byte_read_2.rs @@ -3,6 +3,6 @@ fn main() { let y = &x; let z = &y as *const &i32 as *const u8; // the deref fails, because we are reading only a part of the pointer - let _ = unsafe { *z }; //~ ERROR constant evaluation error [E0080] + let _ = unsafe { *z }; //~ ERROR constant evaluation error //~^ NOTE tried to access part of a pointer value as raw bytes } diff --git a/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs b/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs index 72ae1b123e8a..89cf357e201c 100644 --- a/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs +++ b/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs @@ -1,7 +1,7 @@ fn main() { let x: *const u8 = &1; let y: *const u8 = &2; - if x < y { //~ ERROR constant evaluation error [E0080] + if x < y { //~ ERROR constant evaluation error //~^ NOTE attempted to do invalid arithmetic on pointers unreachable!() } diff --git a/tests/compile-fail/ptr_bitops.rs b/tests/compile-fail/ptr_bitops.rs index 52bcf24cf6b8..ecd47a186efb 100644 --- a/tests/compile-fail/ptr_bitops.rs +++ b/tests/compile-fail/ptr_bitops.rs @@ -2,7 +2,7 @@ fn main() { let bytes = [0i8, 1, 2, 3, 4, 5, 6, 7, 8, 9]; let one = bytes.as_ptr().wrapping_offset(1); let three = bytes.as_ptr().wrapping_offset(3); - let res = (one as usize) | (three as usize); //~ ERROR constant evaluation error [E0080] + let res = (one as usize) | (three as usize); //~ ERROR constant evaluation error //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes println!("{}", res); } diff --git a/tests/compile-fail/ptr_int_cast.rs b/tests/compile-fail/ptr_int_cast.rs index 56403d619ffa..11243921bfd4 100644 --- a/tests/compile-fail/ptr_int_cast.rs +++ b/tests/compile-fail/ptr_int_cast.rs @@ -2,7 +2,7 @@ fn main() { let x = &1; // Casting down to u8 and back up to a pointer loses too much precision; this must not work. let x = x as *const i32; - let x = x as u8; //~ ERROR constant evaluation error [E0080] + let x = x as u8; //~ ERROR constant evaluation error //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes let x = x as *const i32; let _ = unsafe { *x }; diff --git a/tests/compile-fail/reading_half_a_pointer.rs b/tests/compile-fail/reading_half_a_pointer.rs index e44f26c4c4cf..3ea693a3f0fb 100644 --- a/tests/compile-fail/reading_half_a_pointer.rs +++ b/tests/compile-fail/reading_half_a_pointer.rs @@ -24,7 +24,7 @@ fn main() { // starts 1 byte to the right, so using it would actually be wrong! let d_alias = &mut w.data as *mut _ as *mut *const u8; unsafe { - let _x = *d_alias; //~ ERROR constant evaluation error [E0080] + let _x = *d_alias; //~ ERROR constant evaluation error //~^ NOTE tried to access part of a pointer value as raw bytes } } diff --git a/tests/compile-fail/reference_to_packed.rs b/tests/compile-fail/reference_to_packed.rs index 16b452ca0e3c..946a6b89a777 100644 --- a/tests/compile-fail/reference_to_packed.rs +++ b/tests/compile-fail/reference_to_packed.rs @@ -15,6 +15,6 @@ fn main() { y: 99, }; let p = unsafe { &foo.x }; - let i = *p; //~ ERROR constant evaluation error [E0080] + let i = *p; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 1, but alignment 4 is required } diff --git a/tests/compile-fail/static_memory_modification.rs b/tests/compile-fail/static_memory_modification.rs index a85ff545ee42..e28bcb37fb72 100644 --- a/tests/compile-fail/static_memory_modification.rs +++ b/tests/compile-fail/static_memory_modification.rs @@ -4,7 +4,7 @@ static X: usize = 5; #[allow(mutable_transmutes)] fn main() { unsafe { - *std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR constant evaluation error [E0080] + *std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR constant evaluation error //~^ NOTE tried to modify constant memory assert_eq!(X, 6); } diff --git a/tests/compile-fail/static_memory_modification2.rs b/tests/compile-fail/static_memory_modification2.rs index 6abe6de1fcf4..2f702f09c804 100644 --- a/tests/compile-fail/static_memory_modification2.rs +++ b/tests/compile-fail/static_memory_modification2.rs @@ -7,7 +7,7 @@ use std::mem::transmute; fn main() { unsafe { let s = "this is a test"; - transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR constant evaluation error [E0080] + transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR constant evaluation error //~^ NOTE tried to modify constant memory } } diff --git a/tests/compile-fail/static_memory_modification3.rs b/tests/compile-fail/static_memory_modification3.rs index 0891756f0ec6..37d8bfe02ceb 100644 --- a/tests/compile-fail/static_memory_modification3.rs +++ b/tests/compile-fail/static_memory_modification3.rs @@ -4,7 +4,7 @@ use std::mem::transmute; fn main() { unsafe { let bs = b"this is a test"; - transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR constant evaluation error [E0080] + transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR constant evaluation error //~^ NOTE tried to modify constant memory } } diff --git a/tests/compile-fail/transmute-pair-undef.rs b/tests/compile-fail/transmute-pair-undef.rs index 6b4fe2273a08..9509bb60e8b1 100644 --- a/tests/compile-fail/transmute-pair-undef.rs +++ b/tests/compile-fail/transmute-pair-undef.rs @@ -16,6 +16,6 @@ fn main() { assert_eq!(byte, 0); } let v = unsafe { *z.offset(first_undef) }; - if v == 0 {} //~ ERROR constant evaluation error [E0080] + if v == 0 {} //~ ERROR constant evaluation error //~^ NOTE attempted to read undefined bytes } diff --git a/tests/compile-fail/transmute_fat.rs b/tests/compile-fail/transmute_fat.rs index 81d783807c58..dad5f4df2da3 100644 --- a/tests/compile-fail/transmute_fat.rs +++ b/tests/compile-fail/transmute_fat.rs @@ -10,6 +10,6 @@ fn main() { let bad = unsafe { std::mem::transmute::<&[u8], u64>(&[1u8]) }; - let _ = bad + 1; //~ ERROR constant evaluation error [E0080] + let _ = bad + 1; //~ ERROR constant evaluation error //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes } diff --git a/tests/compile-fail/transmute_fat2.rs b/tests/compile-fail/transmute_fat2.rs index 96a713305e6b..e9e21a84294d 100644 --- a/tests/compile-fail/transmute_fat2.rs +++ b/tests/compile-fail/transmute_fat2.rs @@ -7,6 +7,6 @@ fn main() { let bad = unsafe { std::mem::transmute::(42) }; - bad[0]; //~ ERROR constant evaluation error [E0080] + bad[0]; //~ ERROR constant evaluation error //~^ NOTE index out of bounds: the len is 0 but the index is 0 } diff --git a/tests/compile-fail/unaligned_ptr_cast.rs b/tests/compile-fail/unaligned_ptr_cast.rs index cb9523395391..f91def30d120 100644 --- a/tests/compile-fail/unaligned_ptr_cast.rs +++ b/tests/compile-fail/unaligned_ptr_cast.rs @@ -2,6 +2,6 @@ fn main() { let x = &2u16; let x = x as *const _ as *const u32; // This must fail because alignment is violated - let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080] + let _x = unsafe { *x }; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 2, but alignment 4 is required } diff --git a/tests/compile-fail/unaligned_ptr_cast2.rs b/tests/compile-fail/unaligned_ptr_cast2.rs index dee2bbc9972f..f87dab76ba30 100644 --- a/tests/compile-fail/unaligned_ptr_cast2.rs +++ b/tests/compile-fail/unaligned_ptr_cast2.rs @@ -3,6 +3,6 @@ fn main() { let x = x as *const _ as *const *const u8; // This must fail because alignment is violated. Test specifically for loading pointers, which have special code // in miri's memory. - let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080] + let _x = unsafe { *x }; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 2, but alignment } diff --git a/tests/compile-fail/unaligned_ptr_cast_zst.rs b/tests/compile-fail/unaligned_ptr_cast_zst.rs index eba17ab6c640..45016473c975 100644 --- a/tests/compile-fail/unaligned_ptr_cast_zst.rs +++ b/tests/compile-fail/unaligned_ptr_cast_zst.rs @@ -2,6 +2,6 @@ fn main() { let x = &2u16; let x = x as *const _ as *const [u32; 0]; // This must fail because alignment is violated. Test specifically for loading ZST. - let _x = unsafe { *x }; //~ ERROR constant evaluation error [E0080] + let _x = unsafe { *x }; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 2, but alignment 4 is required } diff --git a/tests/compile-fail/wild_pointer_deref.rs b/tests/compile-fail/wild_pointer_deref.rs index 035d979c5b07..4096cfb93e72 100644 --- a/tests/compile-fail/wild_pointer_deref.rs +++ b/tests/compile-fail/wild_pointer_deref.rs @@ -1,6 +1,6 @@ fn main() { let p = 44 as *const i32; - let x = unsafe { *p }; //~ ERROR constant evaluation error [E0080] + let x = unsafe { *p }; //~ ERROR constant evaluation error //~^ NOTE a memory access tried to interpret some bytes as a pointer panic!("this should never print: {}", x); } diff --git a/tests/compile-fail/zst.rs b/tests/compile-fail/zst.rs index d6518a48aa82..efb2dafd36fc 100644 --- a/tests/compile-fail/zst.rs +++ b/tests/compile-fail/zst.rs @@ -1,5 +1,5 @@ fn main() { let x = &() as *const () as *const i32; - let _ = unsafe { *x }; //~ ERROR constant evaluation error [E0080] + let _ = unsafe { *x }; //~ ERROR constant evaluation error //~^ NOTE tried to access memory with alignment 1, but alignment 4 is required }