diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-04-10 14:24:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-10 14:24:19 +0000 |
| commit | 2436ce015349fabc9a07467f476d9835c0fd77d7 (patch) | |
| tree | 2ec5666d7b0a148628bb733f51f13d49ce5ba4c2 | |
| parent | 26eedd8f95476b185b88465f62981bc78230ebbc (diff) | |
| parent | ff008f187742bdb51051fb0ee57b55d5f80616dc (diff) | |
| download | rust-2436ce015349fabc9a07467f476d9835c0fd77d7.tar.gz rust-2436ce015349fabc9a07467f476d9835c0fd77d7.zip | |
Merge pull request #19563 from Veykril/push-xwlnkpmkqnwp
fix: Fix invalid signature bitflags
3 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs index 05c220d223e..eb66e592d68 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs @@ -282,6 +282,9 @@ impl ExpressionStore { } } + /// Walks the immediate children expressions and calls `f` for each child expression. + /// + /// Note that this does not walk const blocks. pub fn walk_child_exprs(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) { let expr = &self[expr_id]; match expr { @@ -415,6 +418,10 @@ impl ExpressionStore { } } + /// Walks the immediate children expressions and calls `f` for each child expression but does + /// not walk expressions within patterns. + /// + /// Note that this does not walk const blocks. pub fn walk_child_exprs_without_pats(&self, expr_id: ExprId, mut f: impl FnMut(ExprId)) { let expr = &self[expr_id]; match expr { 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 ca0f33fa693..73b99db7268 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 @@ -348,6 +348,7 @@ impl<'a> UnsafeVisitor<'a> { Expr::Closure { args, .. } => { self.walk_pats_top(args.iter().copied(), current); } + Expr::Const(e) => self.walk_expr(*e), _ => {} } diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs index a9b481f8998..c851a9c2390 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs @@ -878,4 +878,17 @@ fn f(it: unsafe fn()){ "#, ); } + + #[test] + fn unsafe_call_in_const_expr() { + check_diagnostics( + r#" +unsafe fn f() {} +fn main() { + const { f(); }; + // ^^^ 💡 error: call to unsafe function is unsafe and requires an unsafe function or block +} + "#, + ); + } } |
