Skip to content

Commit 9d2e1ed

Browse files
Make sure to walk into nested const blocks in RegionResolutionVisitor
1 parent 8247594 commit 9d2e1ed

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

compiler/rustc_hir_analysis/src/check/region.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
420420
// properly, we can't miss any types.
421421

422422
match expr.kind {
423-
// Manually recurse over closures and inline consts, because they are the only
424-
// case of nested bodies that share the parent environment.
425-
hir::ExprKind::Closure(&hir::Closure { body, .. })
426-
| hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) => {
423+
// Manually recurse over closures, because they are nested bodies
424+
// that share the parent environment. We handle const blocks in
425+
// `visit_inline_const`.
426+
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
427427
let body = visitor.tcx.hir().body(body);
428428
visitor.visit_body(body);
429429
}
@@ -906,6 +906,10 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
906906
fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) {
907907
resolve_local(self, Some(l.pat), l.init)
908908
}
909+
fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) {
910+
let body = self.tcx.hir().body(c.body);
911+
self.visit_body(body);
912+
}
909913
}
910914

911915
/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @compile-flags: -Zlint-mir
2+
//@ check-pass
3+
4+
#![feature(inline_const_pat)]
5+
6+
fn main() {
7+
match 1 {
8+
const {
9+
|| match 0 {
10+
x => 0,
11+
};
12+
0
13+
} => (),
14+
_ => (),
15+
}
16+
}

0 commit comments

Comments
 (0)