Skip to content

Commit 52ed2c6

Browse files
authored
Rollup merge of #66535 - estebank:issue-62480, r=matthewjasper
Avoid ICE when `break`ing to an unreachable label Fix #62480.
2 parents 4bd9168 + 31620fb commit 52ed2c6

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/librustc_passes/liveness.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
987987
opt_expr.map_or(succ, |expr| self.propagate_through_expr(expr, succ))
988988
}
989989

990-
fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
991-
-> LiveNode {
990+
fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode) -> LiveNode {
992991
debug!("propagate_through_expr: {}", self.ir.tcx.hir().hir_to_pretty_string(expr.hir_id));
993992

994993
match expr.kind {
@@ -1074,7 +1073,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10741073

10751074
match target {
10761075
Some(b) => self.propagate_through_opt_expr(opt_expr.as_ref().map(|e| &**e), b),
1077-
None => span_bug!(expr.span, "break to unknown label")
1076+
None => {
1077+
// FIXME: This should have been checked earlier. Once this is fixed,
1078+
// replace with `delay_span_bug`. (#62480)
1079+
self.ir.tcx.sess.struct_span_err(
1080+
expr.span,
1081+
"`break` to unknown label",
1082+
).emit();
1083+
errors::FatalError.raise()
1084+
}
10781085
}
10791086
}
10801087

src/test/ui/issues/issue-62480.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(label_break_value)]
2+
3+
fn main() {
4+
// This used to ICE during liveness check because `target_id` passed to
5+
// `propagate_through_expr` would be the closure and not the `loop`, which wouldn't be found in
6+
// `self.break_ln`. (#62480)
7+
'a: {
8+
|| break 'a //~ ERROR `break` to unknown label
9+
}
10+
}

src/test/ui/issues/issue-62480.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `break` to unknown label
2+
--> $DIR/issue-62480.rs:8:12
3+
|
4+
LL | || break 'a
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)