Code
use std::cell::UnsafeCell;
unsafe fn get_mut_unchecked<T>(ptr: &UnsafeCell<T>) -> &mut T {
let t = ptr as *const UnsafeCell<T> as *mut T;
unsafe { &mut *t }
}
Current output
--> src/lib.rs:5:14
|
4 | let t = ptr as *const UnsafeCell<T> as *mut T;
| ------------------------------------- casting happened here
5 | unsafe { &mut *t }
| ^^^^^^^
|
= note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
= note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
= note: `#[deny(invalid_reference_casting)]` on by default
Desired output
Rationale and extra context
#159730 relaxed the rules for UnsafeCell. Under the new rules, the given code is equivalent to
unsafe fn get_mut_unchecked<T>(ptr: &UnsafeCell<T>) -> &mut T {
let t = ptr.get();
unsafe { &mut *t }
}
This does not raise a diagnostic either, so there's no longer a reason to raise a diagnostic for the original code.
Cc @Urgau
Other cases
Rust Version
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
#159730 relaxed the rules for UnsafeCell. Under the new rules, the given code is equivalent to
This does not raise a diagnostic either, so there's no longer a reason to raise a diagnostic for the original code.
Cc @Urgau
Other cases
Rust Version
Anything else?
No response