Skip to content

Commit

Permalink
Auto merge of #134464 - Veykril:backport/rust-analyzer/18711, r=Mark-…
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Dec 27, 2024
2 parents 202008a + 840f658 commit 0857a8e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ fn walk_unsafe(
}
Expr::Path(path) => mark_unsafe_path(path, current.into()),
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
if let Expr::Path(_) = body.exprs[*expr] {
// Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
// see https://github.com/rust-lang/rust/pull/125834.
return;
match body.exprs[*expr] {
Expr::Path(_) => return,
// https://github.com/rust-lang/rust/pull/129248
// Taking a raw ref to a deref place expr is always safe.
Expr::UnaryOp { expr, op: UnaryOp::Deref } => {
body.walk_child_exprs(expr, |child| {
walk_unsafe(db, infer, body, resolver, def, child, inside_unsafe_block, unsafe_expr_cb);
});

return;
}
_ => (),
}
}
Expr::MethodCall { .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,4 +631,19 @@ fn main() {
"#,
);
}

#[test]
fn raw_ref_reborrow_is_safe() {
check_diagnostics(
r#"
fn main() {
let ptr: *mut i32;
let _addr = &raw const *ptr;
let local = 1;
let ptr = &local as *const i32;
let _addr = &raw const *ptr;
}
"#,
)
}
}

0 comments on commit 0857a8e

Please sign in to comment.