unsafe {
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
- let _z = *(x.as_ptr() as *mut u8); //~ ERROR constant evaluation error
- //~^ NOTE dangling pointer was dereferenced
+ let _z = *(x.as_ptr() as *mut u8); //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 1, but alignment
+ *y_ptr = 42; //~ ERROR 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
- //~^ NOTE `assume` argument was false
+ std::intrinsics::assume(x > 42); //~ `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
- //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
+ return (p & (u64_align + 1)) == 0; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes
}
pub fn main() {
let x = mk_rec();
- assert!(is_u64_aligned(&x.t)); //~ NOTE inside call to `is_u64_aligned
+ assert!(is_u64_aligned(&x.t));
}
std::mem::transmute::<&usize, &fn(i32)>(&b)
};
- (*g)(42) //~ ERROR constant evaluation error
- //~^ NOTE a memory access tried to interpret some bytes as a pointer
+ (*g)(42) //~ ERROR a memory access tried to interpret some bytes as a pointer
}
std::mem::transmute::<usize, fn(i32)>(42)
};
- g(42) //~ ERROR constant evaluation error
- //~^ NOTE a memory access tried to interpret some bytes as a pointer
+ g(42) //~ ERROR a memory access tried to interpret some bytes as a pointer
}
let b = Box::new(42);
&*b as *const i32
};
- let x = unsafe { *p }; //~ ERROR constant evaluation error
- //~^ NOTE dangling pointer was dereferenced
+ let x = unsafe { *p }; //~ ERROR dangling pointer was dereferenced
panic!("this should never print: {}", x);
}
#![allow(const_err)]
fn main() {
- let _n = 1 / 0; //~ ERROR constant evaluation error
- //~^ NOTE attempt to divide by zero
+ let _n = 1 / 0; //~ ERROR attempt to divide by zero
}
let x = box 42;
unsafe {
let f = std::mem::transmute::<Box<i32>, fn()>(x);
- f() //~ ERROR constant evaluation error
- //~^ NOTE tried to treat a memory pointer as a function pointer
+ f() //~ ERROR 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
- //~^ NOTE tried to use a function pointer after offsetting it
+ x(); //~ ERROR tried to use a function pointer after offsetting it
}
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
- //~^ NOTE tried to modify constant memory
+ *y = 42; //~ ERROR 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
- //~^ NOTE entered unreachable code
+ *(y as *const _ as *const !) //~ ERROR entered unreachable code
};
f(x)
}
enum Void {}
fn f(v: Void) -> ! {
- match v {} //~ ERROR constant evaluation error
- //~^ NOTE entered unreachable code
+ match v {} //~ ERROR entered unreachable code
}
fn main() {
fn main() {
let v: Vec<u8> = vec![1, 2];
- let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR constant evaluation error
- //~^ NOTE which has size 2
+ let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR outside bounds of allocation
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
- //~^ NOTE outside bounds of allocation
+ let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR outside bounds of allocation
panic!("this should never print: {}", x);
}
#![allow(const_err)]
fn main() {
- let _n = 2i64 << -1; //~ ERROR constant evaluation error
- //~^ NOTE attempt to shift left with overflow
+ let _n = 2i64 << -1; //~ ERROR 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
- //~^ NOTE attempt to shift right with overflow
+ let _n = 1i64 >> (u32::max_value() as i64 + 1); //~ ERROR attempt to shift right with overflow
}
#![allow(exceeding_bitshifts)]
fn main() {
- let _n = 1i64 >> 64; //~ ERROR constant evaluation error
- //~^ NOTE attempt to shift right with overflow
+ let _n = 1i64 >> 64; //~ ERROR 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
- //~^ NOTE attempted to read undefined bytes
+ let x = *p; //~ ERROR attempted to read undefined bytes
panic!("this should never print: {}", x);
}
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
- //~^ NOTE tried to access part of a pointer value as raw bytes
+ let _ = unsafe { *z }; //~ ERROR 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
- //~^ NOTE attempted to do invalid arithmetic on pointers
+ if x < y { //~ ERROR attempted to do invalid arithmetic on pointers
unreachable!()
}
}
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
- //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
+ let x = x as u8; //~ ERROR 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
- //~^ NOTE tried to access part of a pointer value as raw bytes
+ let _x = *d_alias; //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 1, but alignment 4 is required
+ let i = *p; //~ ERROR 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
- //~^ NOTE tried to modify constant memory
+ *std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR 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
- //~^ NOTE tried to modify constant memory
+ transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR 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
- //~^ NOTE tried to modify constant memory
+ transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR tried to modify constant memory
}
}
assert_eq!(byte, 0);
}
let v = unsafe { *z.offset(first_undef) };
- if v == 0 {} //~ ERROR constant evaluation error
- //~^ NOTE attempted to read undefined bytes
+ if v == 0 {} //~ ERROR attempted to read undefined bytes
}
let bad = unsafe {
std::mem::transmute::<&[u8], [u8; 8]>(&[1u8])
};
- let _ = bad[0] + bad[bad.len()-1]; //~ ERROR constant evaluation error
- //~^ NOTE a raw memory access tried to access part of a pointer value as raw bytes
+ let _ = bad[0] + bad[bad.len()-1]; //~ ERROR 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
- //~^ NOTE index out of bounds: the len is 0 but the index is 0
+ bad[0]; //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 2, but alignment 4 is required
+ let _x = unsafe { *x }; //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 2, but alignment
+ let _x = unsafe { *x }; //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 2, but alignment 4 is required
+ let _x = unsafe { *x }; //~ ERROR tried to access memory with alignment 2, but alignment 4 is required
}
fn main() {
let v: Vec<u8> = Vec::with_capacity(10);
let undef = unsafe { *v.get_unchecked(5) };
- let x = undef + 1; //~ ERROR: error
- //~^ NOTE attempted to read undefined bytes
+ let x = undef + 1; //~ ERROR attempted to read undefined bytes
panic!("this should never print: {}", x);
}
fn main() {
let p = 44 as *const i32;
- let x = unsafe { *p }; //~ ERROR constant evaluation error
- //~^ NOTE a memory access tried to interpret some bytes as a pointer
+ let x = unsafe { *p }; //~ ERROR 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
- //~^ NOTE tried to access memory with alignment 1, but alignment 4 is required
+ let _ = unsafe { *x }; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required
}