diff options
Diffstat (limited to '')
-rw-r--r-- | tests/ui/lint/reference_casting.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/ui/lint/reference_casting.rs b/tests/ui/lint/reference_casting.rs index fba8789e9..25e0c75f7 100644 --- a/tests/ui/lint/reference_casting.rs +++ b/tests/ui/lint/reference_casting.rs @@ -64,6 +64,10 @@ unsafe fn ref_to_mut() { let _num = &mut *num; //~^ ERROR casting `&T` to `&mut T` is undefined behavior + let cell = &std::cell::UnsafeCell::new(0); + let _num = &mut *(cell as *const _ as *mut i32); + //~^ ERROR casting `&T` to `&mut T` is undefined behavior + unsafe fn generic_ref_cast_mut<T>(this: &T) -> &mut T { &mut *((this as *const _) as *mut _) //~^ ERROR casting `&T` to `&mut T` is undefined behavior @@ -106,6 +110,8 @@ unsafe fn assign_to_ref() { std::mem::transmute::<*const i32, *mut i32>(num), -1i32, ); + *((&std::cell::UnsafeCell::new(0)) as *const _ as *mut i32) = 5; + //~^ ERROR assigning to `&T` is undefined behavior let value = num as *const i32 as *mut i32; *value = 1; @@ -148,6 +154,8 @@ unsafe fn no_warn() { *RAW_PTR = 42; // RAW_PTR is defined outside the function body, // make sure we don't ICE on it when trying to // determine if we should lint on it or not. + let cell = &std::cell::UnsafeCell::new(0); + let _num = &mut *(cell.get() as *mut i32); fn safe_as_mut<T>(x: &std::cell::UnsafeCell<T>) -> &mut T { unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } |