File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -193,10 +193,19 @@ impl<'a> UnsafeVisitor<'a> {
193193 self . resolver . reset_to_guard ( guard) ;
194194 }
195195 Expr :: Ref { expr, rawness : Rawness :: RawPtr , mutability : _ } => {
196- if let Expr :: Path ( _ ) = self . body . exprs [ * expr] {
196+ match self . body . exprs [ * expr] {
197197 // Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
198198 // see https://github.com/rust-lang/rust/pull/125834.
199- return ;
199+ Expr :: Path ( _) => return ,
200+ // https://github.com/rust-lang/rust/pull/129248
201+ // Taking a raw ref to a deref place expr is always safe.
202+ Expr :: UnaryOp { expr, op : UnaryOp :: Deref } => {
203+ self . body
204+ . walk_child_exprs_without_pats ( expr, |child| self . walk_expr ( child) ) ;
205+
206+ return ;
207+ }
208+ _ => ( ) ,
200209 }
201210 }
202211 Expr :: MethodCall { .. } => {
Original file line number Diff line number Diff line change @@ -778,4 +778,20 @@ fn bar(mut v: Union2) {
778778 "# ,
779779 )
780780 }
781+
782+ #[ test]
783+ fn raw_ref_reborrow_is_safe ( ) {
784+ check_diagnostics (
785+ r#"
786+ fn main() {
787+ let ptr: *mut i32;
788+ let _addr = &raw const *ptr;
789+
790+ let local = 1;
791+ let ptr = &local as *const i32;
792+ let _addr = &raw const *ptr;
793+ }
794+ "# ,
795+ )
796+ }
781797}
You can’t perform that action at this time.
0 commit comments