Format tests with rustfmt (225-275 of 300)
This commit is contained in:
parent
cbb649adfe
commit
6827ac2f37
@ -6,7 +6,9 @@ use std::cell::Cell;
|
||||
|
||||
fn helper(val: Box<Cell<u8>>, ptr: *const Cell<u8>) -> u8 {
|
||||
val.set(10);
|
||||
unsafe { (*ptr).set(20); } //~ ERROR does not exist in the borrow stack
|
||||
unsafe {
|
||||
(*ptr).set(20);
|
||||
} //~ ERROR does not exist in the borrow stack
|
||||
val.get()
|
||||
}
|
||||
|
||||
|
@ -7,5 +7,7 @@ fn main() {
|
||||
// Also not assigning directly as that's array initialization, not assignment.
|
||||
let zst_val = [1u8; 0];
|
||||
let ptr = (&0u8 as *const u8).wrapping_sub(0x800) as *mut [u8; 0];
|
||||
unsafe { *ptr = zst_val; } //~ ERROR out-of-bounds
|
||||
unsafe {
|
||||
*ptr = zst_val;
|
||||
} //~ ERROR out-of-bounds
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ fn main() {
|
||||
let mut data = [0u16; 4];
|
||||
let ptr = &mut data[0] as *mut u16;
|
||||
// Even copying 0 elements from NULL should error.
|
||||
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: null pointer is not a valid pointer
|
||||
unsafe {
|
||||
copy_nonoverlapping(std::ptr::null(), ptr, 0);
|
||||
} //~ ERROR: memory access failed: null pointer is not a valid pointer
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ fn main() {
|
||||
let mut data = [0u16; 8];
|
||||
let ptr = (&mut data[0] as *mut u16 as *mut u8).wrapping_add(1) as *mut u16;
|
||||
// Even copying 0 elements to something unaligned should error
|
||||
unsafe { copy_nonoverlapping(&data[5], ptr, 0); } //~ ERROR accessing memory with alignment 1, but alignment 2 is required
|
||||
unsafe {
|
||||
copy_nonoverlapping(&data[5], ptr, 0);
|
||||
} //~ ERROR accessing memory with alignment 1, but alignment 2 is required
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// divison by 0
|
||||
unsafe { std::intrinsics::exact_div(2, 0); } //~ ERROR divisor of zero
|
||||
unsafe {
|
||||
std::intrinsics::exact_div(2, 0);
|
||||
} //~ ERROR divisor of zero
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// divison with a remainder
|
||||
unsafe { std::intrinsics::exact_div(2u16, 3); } //~ ERROR 2_u16 cannot be divided by 3_u16 without remainder
|
||||
unsafe {
|
||||
std::intrinsics::exact_div(2u16, 3);
|
||||
} //~ ERROR 2_u16 cannot be divided by 3_u16 without remainder
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// signed divison with a remainder
|
||||
unsafe { std::intrinsics::exact_div(-19i8, 2); } //~ ERROR -19_i8 cannot be divided by 2_i8 without remainder
|
||||
unsafe {
|
||||
std::intrinsics::exact_div(-19i8, 2);
|
||||
} //~ ERROR -19_i8 cannot be divided by 2_i8 without remainder
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// divison of MIN by -1
|
||||
unsafe { std::intrinsics::exact_div(i64::MIN, -1); } //~ ERROR overflow in signed remainder (dividing MIN by -1)
|
||||
unsafe {
|
||||
std::intrinsics::exact_div(i64::MIN, -1);
|
||||
} //~ ERROR overflow in signed remainder (dividing MIN by -1)
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, i32>(f32::INFINITY); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, i32>(f32::INFINITY);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, i32>(f32::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, i32>(f32::NEG_INFINITY);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, u32>(f32::NAN); } //~ ERROR: cannot be represented in target type `u32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, u32>(f32::NAN);
|
||||
} //~ ERROR: cannot be represented in target type `u32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, u32>(-f32::NAN); } //~ ERROR: cannot be represented in target type `u32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, u32>(-f32::NAN);
|
||||
} //~ ERROR: cannot be represented in target type `u32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, u32>(-1.000000001f32); } //~ ERROR: cannot be represented in target type `u32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, u32>(-1.000000001f32);
|
||||
} //~ ERROR: cannot be represented in target type `u32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, i32>(2147483648.0f32); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, i32>(2147483648.0f32);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, u32>((u32::MAX-127) as f32); } //~ ERROR: cannot be represented in target type `u32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, u32>((u32::MAX - 127) as f32);
|
||||
} //~ ERROR: cannot be represented in target type `u32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f32, i32>(-2147483904.0f32); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f32, i32>(-2147483904.0f32);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u128>(f64::INFINITY); } //~ ERROR: cannot be represented in target type `u128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u128>(f64::INFINITY);
|
||||
} //~ ERROR: cannot be represented in target type `u128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u128>(f64::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `u128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u128>(f64::NEG_INFINITY);
|
||||
} //~ ERROR: cannot be represented in target type `u128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i128>(f64::NEG_INFINITY); } //~ ERROR: cannot be represented in target type `i128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i128>(f64::NEG_INFINITY);
|
||||
} //~ ERROR: cannot be represented in target type `i128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u32>(f64::NAN); } //~ ERROR: cannot be represented in target type `u32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u32>(f64::NAN);
|
||||
} //~ ERROR: cannot be represented in target type `u32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u128>(-1.0000000000001f64); } //~ ERROR: cannot be represented in target type `u128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u128>(-1.0000000000001f64);
|
||||
} //~ ERROR: cannot be represented in target type `u128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i32>(2147483648.0f64); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i32>(2147483648.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i64>(9223372036854775808.0f64); } //~ ERROR: cannot be represented in target type `i64`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i64>(9223372036854775808.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i64`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u64>(18446744073709551616.0f64); } //~ ERROR: cannot be represented in target type `u64`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u64>(18446744073709551616.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `u64`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u128>(u128::MAX as f64); } //~ ERROR: cannot be represented in target type `u128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u128>(u128::MAX as f64);
|
||||
} //~ ERROR: cannot be represented in target type `u128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i128>(240282366920938463463374607431768211455.0f64); } //~ ERROR: cannot be represented in target type `i128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i128>(240282366920938463463374607431768211455.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, u128>(f64::MAX); } //~ ERROR: cannot be represented in target type `u128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, u128>(f64::MAX);
|
||||
} //~ ERROR: cannot be represented in target type `u128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i128>(f64::MIN); } //~ ERROR: cannot be represented in target type `i128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i128>(f64::MIN);
|
||||
} //~ ERROR: cannot be represented in target type `i128`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i32>(-2147483649.0f64); } //~ ERROR: cannot be represented in target type `i32`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i32>(-2147483649.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i32`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i64>(-9223372036854777856.0f64); } //~ ERROR: cannot be represented in target type `i64`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i64>(-9223372036854777856.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i64`
|
||||
}
|
||||
|
@ -6,5 +6,7 @@ extern "rust-intrinsic" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { float_to_int_unchecked::<f64, i128>(-240282366920938463463374607431768211455.0f64); } //~ ERROR: cannot be represented in target type `i128`
|
||||
unsafe {
|
||||
float_to_int_unchecked::<f64, i128>(-240282366920938463463374607431768211455.0f64);
|
||||
} //~ ERROR: cannot be represented in target type `i128`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MAX overflow
|
||||
unsafe { std::intrinsics::unchecked_add(40000u16, 30000); } //~ ERROR overflow executing `unchecked_add`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_add(40000u16, 30000);
|
||||
} //~ ERROR overflow executing `unchecked_add`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MIN overflow
|
||||
unsafe { std::intrinsics::unchecked_add(-30000i16, -8000); } //~ ERROR overflow executing `unchecked_add`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_add(-30000i16, -8000);
|
||||
} //~ ERROR overflow executing `unchecked_add`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MIN/-1 cannot be represented
|
||||
unsafe { std::intrinsics::unchecked_div(i16::MIN, -1); } //~ ERROR overflow in signed division (dividing MIN by -1)
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_div(i16::MIN, -1);
|
||||
} //~ ERROR overflow in signed division (dividing MIN by -1)
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MAX overflow
|
||||
unsafe { std::intrinsics::unchecked_mul(300u16, 250u16); } //~ ERROR overflow executing `unchecked_mul`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_mul(300u16, 250u16);
|
||||
} //~ ERROR overflow executing `unchecked_mul`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MIN overflow
|
||||
unsafe { std::intrinsics::unchecked_mul(1_000_000_000i32, -4); } //~ ERROR overflow executing `unchecked_mul`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_mul(1_000_000_000i32, -4);
|
||||
} //~ ERROR overflow executing `unchecked_mul`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MIN overflow
|
||||
unsafe { std::intrinsics::unchecked_sub(14u32, 22); } //~ ERROR overflow executing `unchecked_sub`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_sub(14u32, 22);
|
||||
} //~ ERROR overflow executing `unchecked_sub`
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(core_intrinsics)]
|
||||
fn main() {
|
||||
// MAX overflow
|
||||
unsafe { std::intrinsics::unchecked_sub(30000i16, -7000); } //~ ERROR overflow executing `unchecked_sub`
|
||||
unsafe {
|
||||
std::intrinsics::unchecked_sub(30000i16, -7000);
|
||||
} //~ ERROR overflow executing `unchecked_sub`
|
||||
}
|
||||
|
@ -7,5 +7,7 @@ extern "Rust" {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe { miri_start_panic(&mut 0); } //~ ERROR unwinding past a stack frame that does not allow unwinding
|
||||
unsafe {
|
||||
miri_start_panic(&mut 0);
|
||||
} //~ ERROR unwinding past a stack frame that does not allow unwinding
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ fn main() {
|
||||
let target = Box::new(42); // has an implicit raw
|
||||
let xref = &*target;
|
||||
{
|
||||
let x : *mut u32 = xref as *const _ as *mut _;
|
||||
unsafe { *x = 42; } // invalidates shared ref, activates raw
|
||||
let x: *mut u32 = xref as *const _ as *mut _;
|
||||
unsafe {
|
||||
*x = 42;
|
||||
} // invalidates shared ref, activates raw
|
||||
}
|
||||
let _x = *xref; //~ ERROR borrow stack
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ fn main() {
|
||||
let target2 = target as *mut _;
|
||||
drop(&mut *target); // reborrow
|
||||
// Now make sure our ref is still the only one.
|
||||
unsafe { *target2 = 13; } //~ ERROR borrow stack
|
||||
unsafe {
|
||||
*target2 = 13;
|
||||
} //~ ERROR borrow stack
|
||||
let _val = *target;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ fn main() {
|
||||
// Make sure raw ptr with raw tag cannot mutate frozen location without breaking the shared ref.
|
||||
let r#ref = ⌖ // freeze
|
||||
let ptr = r#ref as *const _ as *mut _; // raw ptr, with raw tag
|
||||
unsafe { *ptr = 42; } //~ ERROR only grants SharedReadOnly permission
|
||||
unsafe {
|
||||
*ptr = 42;
|
||||
} //~ ERROR only grants SharedReadOnly permission
|
||||
let _val = *r#ref;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ fn main() {
|
||||
fn foo(a: &mut u32, y: *mut u32) -> u32 {
|
||||
*a = 1;
|
||||
let _b = &*a;
|
||||
unsafe { *y = 2; } //~ ERROR: not granting access to tag
|
||||
unsafe {
|
||||
*y = 2;
|
||||
} //~ ERROR: not granting access to tag
|
||||
return *a;
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ fn main() {
|
||||
let raw2 = &mut l as *mut _; // invalidates raw1
|
||||
// Without raw pointer tracking, Stacked Borrows cannot distinguish raw1 and raw2, and thus
|
||||
// fails to realize that raw1 should not be used any more.
|
||||
unsafe { *raw1 = 13; } //~ ERROR does not exist in the borrow stack
|
||||
unsafe { *raw2 = 13; }
|
||||
unsafe {
|
||||
*raw1 = 13;
|
||||
} //~ ERROR does not exist in the borrow stack
|
||||
unsafe {
|
||||
*raw2 = 13;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
fn foo(x: &mut i32) -> i32 {
|
||||
*x = 5;
|
||||
unknown_code(&*x);
|
||||
*x // must return 5
|
||||
*x = 5;
|
||||
unknown_code(&*x);
|
||||
*x // must return 5
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -9,5 +9,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn unknown_code(x: &i32) {
|
||||
unsafe { *(x as *const i32 as *mut i32) = 7; } //~ ERROR only grants SharedReadOnly permission
|
||||
unsafe {
|
||||
*(x as *const i32 as *mut i32) = 7;
|
||||
} //~ ERROR only grants SharedReadOnly permission
|
||||
}
|
||||
|
@ -10,5 +10,7 @@ fn main() {
|
||||
let _raw: *mut i32 = unsafe { mem::transmute(&mut x[0]) };
|
||||
// `raw` still carries a tag, so we get another pointer to the same location that does not carry a tag
|
||||
let raw = (&mut x[1] as *mut i32).wrapping_offset(-1);
|
||||
unsafe { *raw = 13; } //~ ERROR borrow stack
|
||||
unsafe {
|
||||
*raw = 13;
|
||||
} //~ ERROR borrow stack
|
||||
}
|
||||
|
@ -4,5 +4,7 @@ fn main() {
|
||||
let mut x = 42;
|
||||
let raw = &mut x as *mut i32 as usize as *mut i32;
|
||||
let _ptr = &mut x;
|
||||
unsafe { *raw = 13; } //~ ERROR borrow stack
|
||||
unsafe {
|
||||
*raw = 13;
|
||||
} //~ ERROR borrow stack
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ fn main() {
|
||||
let x = &mut [0u8; 3];
|
||||
let base_addr = x as *mut _ as usize;
|
||||
// Manually make sure the pointer is properly aligned.
|
||||
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 };
|
||||
let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr + 1 };
|
||||
let u16_ptr = base_addr_aligned as *mut u16;
|
||||
unsafe { *u16_ptr = 2; } //~ERROR memory with alignment 1, but alignment 2 is required
|
||||
unsafe {
|
||||
*u16_ptr = 2;
|
||||
} //~ERROR memory with alignment 1, but alignment 2 is required
|
||||
println!("{:?}", x);
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
#[repr(u32)]
|
||||
#[derive(Debug)]
|
||||
enum Bool { True }
|
||||
enum Bool {
|
||||
True,
|
||||
}
|
||||
|
||||
fn evil(x: &mut Bool) {
|
||||
let x = x as *mut _ as *mut u32;
|
||||
unsafe { *x = 44; } // out-of-bounds enum tag
|
||||
unsafe {
|
||||
*x = 44;
|
||||
} // out-of-bounds enum tag
|
||||
}
|
||||
|
||||
#[rustfmt::skip] // rustfmt bug: https://github.com/rust-lang/rustfmt/issues/5391
|
||||
|
@ -11,5 +11,7 @@ fn main() {
|
||||
let mut x_box = Box::new(1u8);
|
||||
let x = &mut *x_box as *mut _ as *mut [u8; 0];
|
||||
drop(x_box);
|
||||
unsafe { *x = zst_val; } //~ ERROR dereferenced after this allocation got freed
|
||||
unsafe {
|
||||
*x = zst_val;
|
||||
} //~ ERROR dereferenced after this allocation got freed
|
||||
}
|
||||
|
@ -11,8 +11,12 @@ fn main() {
|
||||
let mut x_box = Box::new(1u8);
|
||||
let x = (&mut *x_box as *mut u8).wrapping_offset(1);
|
||||
// This one is just "at the edge", but still okay
|
||||
unsafe { *(x as *mut [u8; 0]) = zst_val; }
|
||||
unsafe {
|
||||
*(x as *mut [u8; 0]) = zst_val;
|
||||
}
|
||||
// One byte further is OOB.
|
||||
let x = x.wrapping_offset(1);
|
||||
unsafe { *(x as *mut [u8; 0]) = zst_val; } //~ ERROR out-of-bounds
|
||||
unsafe {
|
||||
*(x as *mut [u8; 0]) = zst_val;
|
||||
} //~ ERROR out-of-bounds
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user