summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/reference_casting.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/ui/lint/reference_casting.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/lint/reference_casting.rs')
-rw-r--r--tests/ui/lint/reference_casting.rs8
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 _) }