diff options
| author | Urgau <urgau@numericable.fr> | 2023-10-04 16:03:39 +0200 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2023-10-04 22:06:16 +0200 |
| commit | e46236cceb03a5f58cae91b9d8a1b18040443b5c (patch) | |
| tree | 80c6920fe6bd391b4535abad309aa6b540941fcd /tests/ui/lint/reference_casting.rs | |
| parent | dd513e1150569d2c5605bcdd4b2a6741deea3294 (diff) | |
| download | rust-e46236cceb03a5f58cae91b9d8a1b18040443b5c.tar.gz rust-e46236cceb03a5f58cae91b9d8a1b18040443b5c.zip | |
Clarify `invalid_reference_casting` lint around interior mutable types
Diffstat (limited to 'tests/ui/lint/reference_casting.rs')
| -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 fba8789e999..25e0c75f70d 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 _) } |
