about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-09 22:16:51 +0000
committerMichael Goulet <michael@errs.io>2025-01-09 22:16:51 +0000
commit9d2e1ed6bd86047f724c8bde4f79561024d13fb8 (patch)
tree31f0fc4ef6a8dded882e1e0b28fbefd541177caa
parent824759493246ee383beb9cd5ceffa0e15deb9fa4 (diff)
downloadrust-9d2e1ed6bd86047f724c8bde4f79561024d13fb8.tar.gz
rust-9d2e1ed6bd86047f724c8bde4f79561024d13fb8.zip
Make sure to walk into nested const blocks in RegionResolutionVisitor
-rw-r--r--compiler/rustc_hir_analysis/src/check/region.rs12
-rw-r--r--tests/ui/inline-const/collect-scopes-in-pat.rs16
2 files changed, 24 insertions, 4 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs
index e5f98bdfb7f..daea2e98b03 100644
--- a/compiler/rustc_hir_analysis/src/check/region.rs
+++ b/compiler/rustc_hir_analysis/src/check/region.rs
@@ -420,10 +420,10 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
     // properly, we can't miss any types.
 
     match expr.kind {
-        // Manually recurse over closures and inline consts, because they are the only
-        // case of nested bodies that share the parent environment.
-        hir::ExprKind::Closure(&hir::Closure { body, .. })
-        | hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) => {
+        // Manually recurse over closures, because they are nested bodies
+        // that share the parent environment. We handle const blocks in
+        // `visit_inline_const`.
+        hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
             let body = visitor.tcx.hir().body(body);
             visitor.visit_body(body);
         }
@@ -906,6 +906,10 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
     fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) {
         resolve_local(self, Some(l.pat), l.init)
     }
+    fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) {
+        let body = self.tcx.hir().body(c.body);
+        self.visit_body(body);
+    }
 }
 
 /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
diff --git a/tests/ui/inline-const/collect-scopes-in-pat.rs b/tests/ui/inline-const/collect-scopes-in-pat.rs
new file mode 100644
index 00000000000..024fde53741
--- /dev/null
+++ b/tests/ui/inline-const/collect-scopes-in-pat.rs
@@ -0,0 +1,16 @@
+// @compile-flags: -Zlint-mir
+//@ check-pass
+
+#![feature(inline_const_pat)]
+
+fn main() {
+    match 1 {
+        const {
+            || match 0 {
+                x => 0,
+            };
+            0
+        } => (),
+        _ => (),
+    }
+}