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));
}
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
}
}
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");
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
}
}
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
}
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
}
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)
}
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)
}
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
}
unsafe {
use rusti::*;
- ctlz_nonzero(0u8); //~ ERROR constant evaluation error [E0080]
+ ctlz_nonzero(0u8); //~ ERROR constant evaluation error
//~^ NOTE ctlz_nonzero called on 0
}
}
unsafe {
use rusti::*;
- cttz_nonzero(0u8); //~ ERROR constant evaluation error [E0080]
+ cttz_nonzero(0u8); //~ ERROR constant evaluation error
//~^ NOTE cttz_nonzero called on 0
}
}
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);
}
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);
#![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
}
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
}
}
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
}
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
}
Foo::C => {},
Foo::D => {},
}
-} //~ ERROR constant evaluation error [E0080]
+} //~ ERROR constant evaluation error
//~^ NOTE entered unreachable code
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' => {},
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);
}
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)
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)
enum Void {}
fn f(v: Void) -> ! {
- match v {} //~ ERROR constant evaluation error [E0080]
+ match v {} //~ ERROR constant evaluation error
//~^ NOTE entered unreachable code
}
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);
}
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);
}
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);
}
#![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
}
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
}
#![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
}
// "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);
}
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
}
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
}
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!()
}
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);
}
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 };
// 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
}
}
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
}
#[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);
}
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
}
}
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
}
}
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
}
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
}
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
}
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
}
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
}
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
}
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);
}
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
}