Skip to content

Commit

Permalink
Adjust tests for newly uplifted cast_ref_to_mut lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed May 31, 2023
1 parent 0169ace commit 32d4e1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/modifying_constants.rs
Original file line number Diff line number Diff line change
@@ -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) };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(cast_ref_to_mut)]

fn foo(x: &mut i32) -> i32 {
*x = 5;
unknown_code(&*x);
Expand Down
1 change: 1 addition & 0 deletions tests/ui/const-generics/issues/issue-100313.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl <const B: &'static bool> T<B> {
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
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions tests/ui/const-generics/issues/issue-100313.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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`.

0 comments on commit 32d4e1c

Please sign in to comment.