Skip to content

Commit

Permalink
Adjust some tests for invalid_reference_casting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Jul 29, 2023
1 parent 20a6b57 commit 507d497
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,8 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
/// on an _exclusive_ `UnsafeCell<T>`. Even though `T` and `UnsafeCell<T>` have the
/// same memory layout, the following is not allowed and undefined behavior:
///
/// ```rust,no_run
#[cfg_attr(bootstrap, doc = "```rust,no_run")]
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
/// # use std::cell::UnsafeCell;
/// unsafe fn not_allowed<T>(ptr: &UnsafeCell<T>) -> &mut T {
/// let t = ptr as *const UnsafeCell<T> as *mut T;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/both_borrows/illegal_write1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows

#![allow(invalid_reference_casting)]

fn main() {
let target = Box::new(42); // has an implicit raw
let xref = &*target;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/fail/stacked_borrows/illegal_write3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(invalid_reference_casting)]

fn main() {
let target = 42;
// Make sure raw ptr with raw tag cannot mutate frozen location without breaking the shared ref.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/issues/issue-100313.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +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
//~| ERROR assigning to `&T` is undefined behavior
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/const-generics/issues/issue-100313.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
--> $DIR/issue-100313.rs:10:13
|
LL | *(B as *const bool as *mut bool) = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(invalid_reference_casting)]` on by default

Expand Down

0 comments on commit 507d497

Please sign in to comment.