mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge pull request #18711 from Veykril/push-kwurwxttmqwo
Taking a raw ref of a deref is always safe
This commit is contained in:
commit
c70b07b3c9
2 changed files with 27 additions and 2 deletions
|
@ -193,11 +193,20 @@ impl<'a> UnsafeVisitor<'a> {
|
||||||
self.resolver.reset_to_guard(guard);
|
self.resolver.reset_to_guard(guard);
|
||||||
}
|
}
|
||||||
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
|
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
|
||||||
if let Expr::Path(_) = self.body.exprs[*expr] {
|
match self.body.exprs[*expr] {
|
||||||
// Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
|
// Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
|
||||||
// see https://github.com/rust-lang/rust/pull/125834.
|
// see https://github.com/rust-lang/rust/pull/125834.
|
||||||
|
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 } => {
|
||||||
|
self.body
|
||||||
|
.walk_child_exprs_without_pats(expr, |child| self.walk_expr(child));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Expr::MethodCall { .. } => {
|
Expr::MethodCall { .. } => {
|
||||||
if self
|
if self
|
||||||
|
|
|
@ -778,4 +778,20 @@ fn bar(mut v: Union2) {
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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…
Reference in a new issue