Skip to content

Commit e4c2323

Browse files
authored
Rollup merge of rust-lang#115100 - Urgau:invalid_ref_casting-ptr-writes, r=est31
Add support for `ptr::write`s for the `invalid_reference_casting` lint This PR adds support for `ptr::write` and others for the `invalid_reference_casting` lint. Detecting instances where instead of using the deref (`*`) operator to assign someone uses `ptr::write`, `ptr::write_unaligned` or `ptr::write_volatile`. ```rust let data_len = 5u64; std::ptr::write( std::mem::transmute::<*const u64, *mut u64>(&data_len), new_data_len, ); ``` r? ``@est31``
2 parents eb3b48d + 26a167a commit e4c2323

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

core/src/ptr/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
13571357
#[inline]
13581358
#[stable(feature = "rust1", since = "1.0.0")]
13591359
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1360+
#[rustc_diagnostic_item = "ptr_write"]
13601361
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13611362
pub const unsafe fn write<T>(dst: *mut T, src: T) {
13621363
// Semantically, it would be fine for this to be implemented as a
@@ -1459,6 +1460,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
14591460
#[inline]
14601461
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
14611462
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1463+
#[rustc_diagnostic_item = "ptr_write_unaligned"]
14621464
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14631465
pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
14641466
// SAFETY: the caller must guarantee that `dst` is valid for writes.
@@ -1607,6 +1609,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
16071609
/// ```
16081610
#[inline]
16091611
#[stable(feature = "volatile", since = "1.9.0")]
1612+
#[rustc_diagnostic_item = "ptr_write_volatile"]
16101613
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
16111614
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
16121615
// SAFETY: the caller must uphold the safety contract for `volatile_store`.

0 commit comments

Comments
 (0)