Auto merge of #134464 - Veykril:backport/rust-analyzer/18711, r=Mark-Simulacrum
[beta] Backport rust-lang/rust-analyzer#18711 rust-lang/rust-analyzer#18711
This commit is contained in:
commit
0857a8e32c
2 changed files with 27 additions and 4 deletions
|
@ -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 { .. } => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue