Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0857a8e

Browse files
committed
Auto merge of #134464 - Veykril:backport/rust-analyzer/18711, r=Mark-Simulacrum
[beta] Backport rust-lang/rust-analyzer#18711 rust-lang/rust-analyzer#18711
2 parents 202008a + 840f658 commit 0857a8e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

‎src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,18 @@ fn walk_unsafe(
9999
}
100100
Expr::Path(path) => mark_unsafe_path(path, current.into()),
101101
Expr::Ref { expr, rawness: Rawness::RawPtr, mutability: _ } => {
102-
if let Expr::Path(_) = body.exprs[*expr] {
103-
// Do not report unsafe for `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`,
104-
// see https://github.com/rust-lang/rust/pull/125834.
105-
return;
102+
match body.exprs[*expr] {
103+
Expr::Path(_) => return,
104+
// https://github.com/rust-lang/rust/pull/129248
105+
// Taking a raw ref to a deref place expr is always safe.
106+
Expr::UnaryOp { expr, op: UnaryOp::Deref } => {
107+
body.walk_child_exprs(expr, |child| {
108+
walk_unsafe(db, infer, body, resolver, def, child, inside_unsafe_block, unsafe_expr_cb);
109+
});
110+
111+
return;
112+
}
113+
_ => (),
106114
}
107115
}
108116
Expr::MethodCall { .. } => {

‎src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,19 @@ fn main() {
631631
"#,
632632
);
633633
}
634+
635+
#[test]
636+
fn raw_ref_reborrow_is_safe() {
637+
check_diagnostics(
638+
r#"
639+
fn main() {
640+
let ptr: *mut i32;
641+
let _addr = &raw const *ptr;
642+
let local = 1;
643+
let ptr = &local as *const i32;
644+
let _addr = &raw const *ptr;
645+
}
646+
"#,
647+
)
648+
}
634649
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /