Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7b61f7f

Browse files
committed
Don't create drop scopes after item statements
These scopes would not exist in MIR and can cause ICEs with invalid uses of let expressions.
1 parent 7d1e416 commit 7b61f7f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
149149
// From now on, we continue normally.
150150
visitor.cx = prev_cx;
151151
}
152-
hir::StmtKind::Local(..) | hir::StmtKind::Item(..) => {
152+
hir::StmtKind::Local(..)=> {
153153
// Each declaration introduces a subscope for bindings
154154
// introduced by the declaration; this subscope covers a
155155
// suffix of the block. Each subscope in a block has the
@@ -163,6 +163,10 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
163163
visitor.cx.var_parent = visitor.cx.parent;
164164
visitor.visit_stmt(statement)
165165
}
166+
hir::StmtKind::Item(..) => {
167+
// Don't create scopes for items, since they won't be
168+
// lowered to THIR and MIR.
169+
}
166170
hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => visitor.visit_stmt(statement),
167171
}
168172
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for #104172
2+
3+
const N: usize = {
4+
struct U;
5+
!let y = 42;
6+
//~^ ERROR expected expression, found `let` statement
7+
//~| ERROR `let` expressions are not supported here
8+
//~| ERROR `let` expressions in this position are unstable [E0658]
9+
3
10+
};
11+
12+
struct S {
13+
x: [(); N]
14+
}
15+
16+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: expected expression, found `let` statement
2+
--> $DIR/avoid-invalid-mir.rs:5:7
3+
|
4+
LL | ! let y = 42;
5+
| ^^^
6+
7+
error: `let` expressions are not supported here
8+
--> $DIR/avoid-invalid-mir.rs:5:7
9+
|
10+
LL | ! let y = 42;
11+
| ^^^^^^^^^^
12+
|
13+
= note: only supported directly in conditions of `if` and `while` expressions
14+
15+
error[E0658]: `let` expressions in this position are unstable
16+
--> $DIR/avoid-invalid-mir.rs:5:7
17+
|
18+
LL | ! let y = 42;
19+
| ^^^^^^^^^^
20+
|
21+
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
22+
= help: add `#![feature(let_chains)]` to the crate attributes to enable
23+
24+
error: aborting due to 3 previous errors
25+
26+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)