about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/hir-def/src/body/scope.rs10
-rw-r--r--crates/hir-ty/src/diagnostics/unsafe_check.rs2
2 files changed, 11 insertions, 1 deletions
diff --git a/crates/hir-def/src/body/scope.rs b/crates/hir-def/src/body/scope.rs
index 2617d4288a3..e7078b7953b 100644
--- a/crates/hir-def/src/body/scope.rs
+++ b/crates/hir-def/src/body/scope.rs
@@ -194,6 +194,16 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
             scopes.set_scope(expr, scope);
             compute_block_scopes(statements, *tail, body, scopes, &mut scope);
         }
+        Expr::Unsafe { id, statements, tail }
+        | Expr::Async { id, statements, tail }
+        | Expr::Const { id, statements, tail }
+        | Expr::TryBlock { id, statements, tail } => {
+            let mut scope = scopes.new_block_scope(*scope, *id, None);
+            // Overwrite the old scope for the block expr, so that every block scope can be found
+            // via the block itself (important for blocks that only contain items, no expressions).
+            scopes.set_scope(expr, scope);
+            compute_block_scopes(statements, *tail, body, scopes, &mut scope);
+        }
         Expr::For { iterable, pat, body: body_expr, label } => {
             compute_expr_scopes(*iterable, body, scopes, scope);
             let mut scope = scopes.new_labeled_scope(*scope, make_label(label));
diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs
index 9a32a9e92ce..d25c0ccf00d 100644
--- a/crates/hir-ty/src/diagnostics/unsafe_check.rs
+++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs
@@ -95,7 +95,7 @@ fn walk_unsafe(
             }
         }
         Expr::Unsafe { .. } => {
-            expr.walk_child_exprs(|child| {
+            return expr.walk_child_exprs(|child| {
                 walk_unsafe(db, infer, def, body, child, true, unsafe_expr_cb);
             });
         }