Taking a raw ref of a deref is always safe
This commit is contained in:
parent
202008a1b8
commit
840f6588cc
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::Path(path) => mark_unsafe_path(path, current.into()),
|
||||||
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
|
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
|
||||||
if let Expr::Path(_) = body.exprs[*expr] {
|
match body.exprs[*expr] {
|
||||||
// Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
|
Expr::Path(_) => return,
|
||||||
// see https://github.com/rust-lang/rust/pull/125834.
|
// https://github.com/rust-lang/rust/pull/129248
|
||||||
return;
|
// 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 { .. } => {
|
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