Skip to content

Commit fdc05ab

Browse files
committed
Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstrieb
Improve `invalid_reference_casting` lint This PR is a follow-up to rust-lang/rust#111567 and rust-lang/rust#113422. This PR does multiple things: - First it adds support for deferred de-reference, the goal is to support code like this, where the casting and de-reference are not done on the same expression ```rust let myself = self as *const Self as *mut Self; *myself = Self::Ready(value); ``` - Second it does not lint anymore on SB/TB UB code by only checking assignments (`=`, `+=`, ...) and creation of mutable references `&mut *` - Thirdly it greatly improves the diagnostics in particular for cast from `&mut` to `&mut` or assignments - ~~And lastly it renames the lint from `cast_ref_to_mut` to `invalid_reference_casting` which is more consistent with the ["rules"](rust-lang/rust-clippy#2845) and also more consistent with what the lint checks~~ *rust-lang/rust#113422 This PR is best reviewed commit by commit. r? compiler
2 parents ed236a6 + 14f5750 commit fdc05ab

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

tests/fail/both_borrows/illegal_write1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@revisions: stack tree
22
//@[tree]compile-flags: -Zmiri-tree-borrows
33

4+
#![allow(invalid_reference_casting)]
5+
46
fn main() {
57
let target = Box::new(42); // has an implicit raw
68
let xref = &*target;

tests/fail/stacked_borrows/illegal_write3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(invalid_reference_casting)]
2+
13
fn main() {
24
let target = 42;
35
// Make sure raw ptr with raw tag cannot mutate frozen location without breaking the shared ref.

0 commit comments

Comments
 (0)