Skip to content

Commit d6964ca

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 24bece8 commit d6964ca

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/region.rs

+5-1
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
}
+16
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() {}
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)