diff options
| author | Urgau <urgau@numericable.fr> | 2023-05-14 18:51:52 +0200 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2023-05-31 13:42:53 +0200 |
| commit | 32d4e1c3c71fa30c83405eee7ff8b9bba6a903f0 (patch) | |
| tree | cd274dc549cc794b55aa4e39166283c78258fd1c | |
| parent | 0169ace0e2709d1c31b8166f47e3549ea5d6ced9 (diff) | |
| download | rust-32d4e1c3c71fa30c83405eee7ff8b9bba6a903f0.tar.gz rust-32d4e1c3c71fa30c83405eee7ff8b9bba6a903f0.zip | |
Adjust tests for newly uplifted cast_ref_to_mut lint
4 files changed, 15 insertions, 2 deletions
diff --git a/src/tools/miri/tests/fail/modifying_constants.rs b/src/tools/miri/tests/fail/modifying_constants.rs index 2783ebd155f..40ba31dad8f 100644 --- a/src/tools/miri/tests/fail/modifying_constants.rs +++ b/src/tools/miri/tests/fail/modifying_constants.rs @@ -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) }; diff --git a/src/tools/miri/tests/fail/stacked_borrows/shr_frozen_violation1.rs b/src/tools/miri/tests/fail/stacked_borrows/shr_frozen_violation1.rs index d1322dc6e57..8cd59b3550d 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/shr_frozen_violation1.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/shr_frozen_violation1.rs @@ -1,3 +1,5 @@ +#![allow(cast_ref_to_mut)] + fn foo(x: &mut i32) -> i32 { *x = 5; unknown_code(&*x); diff --git a/tests/ui/const-generics/issues/issue-100313.rs b/tests/ui/const-generics/issues/issue-100313.rs index 4e9d3626aa8..9a9d4721c84 100644 --- a/tests/ui/const-generics/issues/issue-100313.rs +++ b/tests/ui/const-generics/issues/issue-100313.rs @@ -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 } } } diff --git a/tests/ui/const-generics/issues/issue-100313.stderr b/tests/ui/const-generics/issues/issue-100313.stderr index d4b486376ca..ffc34a3a41e 100644 --- a/tests/ui/const-generics/issues/issue-100313.stderr +++ b/tests/ui/const-generics/issues/issue-100313.stderr @@ -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`. |
