diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-08-29 22:58:26 +0300 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-08-29 22:58:26 +0300 |
| commit | 0dfe40f0a38ed31ff9ef0e14fd24c5585bb869cd (patch) | |
| tree | 65c39faaa0047f956fd3af8906341b9ffbd15ebb /src/tools/rust-analyzer/crates/hir-ty | |
| parent | 8bb235baa2b8c46c02557ad0500e75c81d270075 (diff) | |
| download | rust-0dfe40f0a38ed31ff9ef0e14fd24c5585bb869cd.tar.gz rust-0dfe40f0a38ed31ff9ef0e14fd24c5585bb869cd.zip | |
Do not report missing unsafe on `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`
The compiler no longer does as well; see https://github.com/rust-lang/rust/pull/125834.
Diffstat (limited to 'src/tools/rust-analyzer/crates/hir-ty')
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs index 1582cbba880..309e208a9aa 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -5,6 +5,7 @@ use hir_def::{ body::Body, hir::{Expr, ExprId, UnaryOp}, resolver::{resolver_for_expr, ResolveValueResult, Resolver, ValueNs}, + type_ref::Rawness, DefWithBodyId, }; @@ -94,6 +95,13 @@ fn walk_unsafe( } resolver.reset_to_guard(g); } + 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; + } + } Expr::MethodCall { .. } => { if infer .method_resolution(current) |
