Adjust tests for newly uplifted cast_ref_to_mut lint

This commit is contained in:
Urgau 2023-05-14 18:51:52 +02:00
parent 0169ace0e2
commit 32d4e1c3c7
4 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,8 @@
// This should fail even without validation/SB
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
#![allow(cast_ref_to_mut)]
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) };

View file

@ -1,3 +1,5 @@
#![allow(cast_ref_to_mut)]
fn foo(x: &mut i32) -> i32 {
*x = 5;
unknown_code(&*x);

View file

@ -9,6 +9,7 @@ const fn set_false(&self) {
unsafe {
*(B as *const bool as *mut bool) = false;
//~^ ERROR evaluation of constant value failed [E0080]
//~| ERROR casting `&T` to `&mut T` is undefined behavior
}
}
}

View file

@ -1,3 +1,11 @@
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
--> $DIR/issue-100313.rs:10:13
|
LL | *(B as *const bool as *mut bool) = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(cast_ref_to_mut)]` on by default
error[E0080]: evaluation of constant value failed
--> $DIR/issue-100313.rs:10:13
|
@ -10,11 +18,11 @@ note: inside `T::<&true>::set_false`
LL | *(B as *const bool as *mut bool) = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `_`
--> $DIR/issue-100313.rs:18:5
--> $DIR/issue-100313.rs:19:5
|
LL | x.set_false();
| ^^^^^^^^^^^^^
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.