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.
This commit is contained in:
parent
7d1e416d32
commit
7b61f7f002
@ -149,7 +149,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
|
||||
// From now on, we continue normally.
|
||||
visitor.cx = prev_cx;
|
||||
}
|
||||
hir::StmtKind::Local(..) | hir::StmtKind::Item(..) => {
|
||||
hir::StmtKind::Local(..)=> {
|
||||
// Each declaration introduces a subscope for bindings
|
||||
// introduced by the declaration; this subscope covers a
|
||||
// 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
|
||||
visitor.cx.var_parent = visitor.cx.parent;
|
||||
visitor.visit_stmt(statement)
|
||||
}
|
||||
hir::StmtKind::Item(..) => {
|
||||
// Don't create scopes for items, since they won't be
|
||||
// lowered to THIR and MIR.
|
||||
}
|
||||
hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => visitor.visit_stmt(statement),
|
||||
}
|
||||
}
|
||||
|
16
tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.rs
Normal file
16
tests/ui/rfcs/rfc-2497-if-let-chains/avoid-invalid-mir.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Regression test for #104172
|
||||
|
||||
const N: usize = {
|
||||
struct U;
|
||||
!let y = 42;
|
||||
//~^ ERROR expected expression, found `let` statement
|
||||
//~| ERROR `let` expressions are not supported here
|
||||
//~| ERROR `let` expressions in this position are unstable [E0658]
|
||||
3
|
||||
};
|
||||
|
||||
struct S {
|
||||
x: [(); N]
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,26 @@
|
||||
error: expected expression, found `let` statement
|
||||
--> $DIR/avoid-invalid-mir.rs:5:7
|
||||
|
|
||||
LL | ! let y = 42;
|
||||
| ^^^
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/avoid-invalid-mir.rs:5:7
|
||||
|
|
||||
LL | ! let y = 42;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: only supported directly in conditions of `if` and `while` expressions
|
||||
|
||||
error[E0658]: `let` expressions in this position are unstable
|
||||
--> $DIR/avoid-invalid-mir.rs:5:7
|
||||
|
|
||||
LL | ! let y = 42;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
|
||||
= help: add `#![feature(let_chains)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
Loading…
x
Reference in New Issue
Block a user