File tree 2 files changed +26
-4
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -99,10 +99,17 @@ fn walk_unsafe(
99
99
}
100
100
Expr :: Path ( path) => mark_unsafe_path ( path, current. into ( ) ) ,
101
101
Expr :: Ref { expr, rawness : Rawness :: RawPtr , mutability : _ } => {
102
- if let Expr :: Path ( _) = body. exprs [ * expr] {
103
- // Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
104
- // see https://github.com/rust-lang/rust/pull/125834.
105
- return ;
102
+ match self . body . exprs [ * expr] {
103
+ Expr :: Path ( _) => return ,
104
+ // https://github.com/rust-lang/rust/pull/129248
105
+ // Taking a raw ref to a deref place expr is always safe.
106
+ Expr :: UnaryOp { expr, op : UnaryOp :: Deref } => {
107
+ self . body
108
+ . walk_child_exprs_without_pats ( expr, |child| self . walk_expr ( child) ) ;
109
+
110
+ return ;
111
+ }
112
+ _ => ( ) ,
106
113
}
107
114
}
108
115
Expr :: MethodCall { .. } => {
Original file line number Diff line number Diff line change @@ -631,4 +631,19 @@ fn main() {
631
631
"# ,
632
632
) ;
633
633
}
634
+
635
+ #[ test]
636
+ fn raw_ref_reborrow_is_safe ( ) {
637
+ check_diagnostics (
638
+ r#"
639
+ fn main() {
640
+ let ptr: *mut i32;
641
+ let _addr = &raw const *ptr;
642
+ let local = 1;
643
+ let ptr = &local as *const i32;
644
+ let _addr = &raw const *ptr;
645
+ }
646
+ "# ,
647
+ )
648
+ }
634
649
}
You can’t perform that action at this time.
0 commit comments