Skip to content

Commit 972d8da

Browse files
committed
The ordinary lowering of thir::ExprKind::Let is unreachable
After desugaring, `let` expressions should only appear inside `if` expressions or `match` guards, possibly nested within a let-chain. In both cases they are specifically handled by the lowerings of those expressions, so this case is currently unreachable.
1 parent 4cdd205 commit 972d8da

File tree

1 file changed

+6
-32
lines changed
  • compiler/rustc_mir_build/src/build/expr

1 file changed

+6
-32
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+6-32
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
109109
this.cfg.goto(else_blk, source_info, join_block);
110110
join_block.unit()
111111
}
112-
ExprKind::Let { expr, ref pat } => {
113-
let scope = this.local_scope();
114-
let (true_block, false_block) = this.in_if_then_scope(scope, expr_span, |this| {
115-
this.lower_let_expr(block, expr, pat, scope, None, expr_span, true)
116-
});
117-
118-
this.cfg.push_assign_constant(
119-
true_block,
120-
source_info,
121-
destination,
122-
ConstOperand {
123-
span: expr_span,
124-
user_ty: None,
125-
const_: Const::from_bool(this.tcx, true),
126-
},
127-
);
128-
129-
this.cfg.push_assign_constant(
130-
false_block,
131-
source_info,
132-
destination,
133-
ConstOperand {
134-
span: expr_span,
135-
user_ty: None,
136-
const_: Const::from_bool(this.tcx, false),
137-
},
138-
);
139-
140-
let join_block = this.cfg.start_new_block();
141-
this.cfg.goto(true_block, source_info, join_block);
142-
this.cfg.goto(false_block, source_info, join_block);
143-
join_block.unit()
112+
ExprKind::Let { .. } => {
113+
// After desugaring, `let` expressions should only appear inside `if`
114+
// expressions or `match` guards, possibly nested within a let-chain.
115+
// In both cases they are specifically handled by the lowerings of
116+
// those expressions, so this case is currently unreachable.
117+
span_bug!(expr_span, "unexpected let expression outside of if or match-guard");
144118
}
145119
ExprKind::NeverToAny { source } => {
146120
let source_expr = &this.thir[source];

0 commit comments

Comments
 (0)