Skip to content

Commit 6c107e0

Browse files
committed
Auto merge of rust-lang#115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, r=est31
Lint on invalid usage of `UnsafeCell::raw_get` in reference casting This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint. The goal of this is to catch those kind of invalid reference casting: ```rust fn as_mut<T>(x: &T) -> &mut T { unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } //~^ ERROR casting `&T` to `&mut T` is undefined behavior } ``` r? `@est31`
2 parents 5fb4475 + d1f6892 commit 6c107e0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

core/src/cell.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,7 @@ impl<T: ?Sized> UnsafeCell<T> {
21652165
#[inline(always)]
21662166
#[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
21672167
#[rustc_const_stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
2168+
#[rustc_diagnostic_item = "unsafe_cell_raw_get"]
21682169
pub const fn raw_get(this: *const Self) -> *mut T {
21692170
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
21702171
// #[repr(transparent)]. This exploits std's special status, there is

0 commit comments

Comments
 (0)