make sure we show error messages even when we cannot show span
This commit is contained in:
parent
4112822a84
commit
30185d09f6
48 changed files with 51 additions and 49 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ fn mk_rec() -> Rec {
|
|||
fn is_u64_aligned(u: &Tag<u64>) -> bool {
|
||||
let p: usize = unsafe { mem::transmute(u) };
|
||||
let u64_align = std::mem::align_of::<u64>();
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ fn main() {
|
|||
std::mem::transmute::<fn(), fn(i32)>(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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ fn main() {
|
|||
std::mem::transmute::<fn((i32,i32)), fn(i32)>(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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ fn main() {
|
|||
std::mem::transmute::<usize, fn(i32)>(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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ fn f() {}
|
|||
|
||||
fn main() {
|
||||
let x: i32 = unsafe {
|
||||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR constant evaluation error [E0080]
|
||||
*std::mem::transmute::<fn(), *const i32>(f) //~ ERROR constant evaluation error
|
||||
//~^ NOTE tried to dereference a function pointer
|
||||
};
|
||||
panic!("this should never print: {}", x);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
let x = box 42;
|
||||
unsafe {
|
||||
let f = std::mem::transmute::<Box<i32>, fn()>(x);
|
||||
f() //~ ERROR constant evaluation error [E0080]
|
||||
f() //~ ERROR constant evaluation error
|
||||
//~^ NOTE tried to treat a memory pointer as a function pointer
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn main() {
|
||||
let b = unsafe { std::mem::transmute::<u8, bool>(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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@ fn main() {
|
|||
Foo::C => {},
|
||||
Foo::D => {},
|
||||
}
|
||||
} //~ ERROR constant evaluation error [E0080]
|
||||
} //~ ERROR constant evaluation error
|
||||
//~^ NOTE entered unreachable code
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
fn main() {
|
||||
assert!(std::char::from_u32(-1_i32 as u32).is_none());
|
||||
match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR constant evaluation error [E0080]
|
||||
match unsafe { std::mem::transmute::<i32, char>(-1) } { //~ ERROR constant evaluation error
|
||||
//~^ NOTE tried to interpret an invalid 32-bit value as a char: 4294967295
|
||||
'a' => {},
|
||||
'b' => {},
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ struct Human;
|
|||
|
||||
fn main() {
|
||||
let x: ! = unsafe {
|
||||
std::mem::transmute::<Human, !>(Human) //~ ERROR constant evaluation error [E0080]
|
||||
std::mem::transmute::<Human, !>(Human) //~ ERROR constant evaluation error
|
||||
//^~ NOTE entered unreachable code
|
||||
};
|
||||
f(x)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
let v: Vec<u8> = 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ fn main() {
|
|||
let bad = unsafe {
|
||||
std::mem::transmute::<u64, &[u8]>(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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue