Skip to content

Commit

Permalink
Rollup merge of #66535 - estebank:issue-62480, r=matthewjasper
Browse files Browse the repository at this point in the history
Avoid ICE when `break`ing to an unreachable label

Fix #62480.
  • Loading branch information
Centril authored Nov 20, 2019
2 parents 4bd9168 + 31620fb commit 52ed2c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustc_passes/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
opt_expr.map_or(succ, |expr| self.propagate_through_expr(expr, succ))
}

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

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

match target {
Some(b) => self.propagate_through_opt_expr(opt_expr.as_ref().map(|e| &**e), b),
None => span_bug!(expr.span, "break to unknown label")
None => {
// FIXME: This should have been checked earlier. Once this is fixed,
// replace with `delay_span_bug`. (#62480)
self.ir.tcx.sess.struct_span_err(
expr.span,
"`break` to unknown label",
).emit();
errors::FatalError.raise()
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/issues/issue-62480.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(label_break_value)]

fn main() {
// This used to ICE during liveness check because `target_id` passed to
// `propagate_through_expr` would be the closure and not the `loop`, which wouldn't be found in
// `self.break_ln`. (#62480)
'a: {
|| break 'a //~ ERROR `break` to unknown label
}
}
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-62480.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `break` to unknown label
--> $DIR/issue-62480.rs:8:12
|
LL | || break 'a
| ^^^^^^^^

error: aborting due to previous error

0 comments on commit 52ed2c6

Please sign in to comment.