Skip to content

Commit

Permalink
CheckLoopVisitor: also visit break expressions
Browse files Browse the repository at this point in the history
Fixes #50802
  • Loading branch information
est31 committed May 17, 2018
1 parent 0e325d0 commit 5e30f6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc_passes/loops.rs
Expand Up @@ -89,6 +89,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
self.with_context(LabeledBlock, |v| v.visit_block(&b));
}
hir::ExprBreak(label, ref opt_expr) => {
opt_expr.as_ref().map(|e| self.visit_expr(e));

if self.require_label_in_labeled_block(e.span, &label, "break") {
// If we emitted an error about an unlabeled break in a labeled
// block, we don't need any further checking for this break any more
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/issue-50802.rs
@@ -0,0 +1,18 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[allow(unreachable_code)]

fn main() {
loop {
break while continue { //~ ERROR E0590
}
}
}
9 changes: 9 additions & 0 deletions src/test/ui/issue-50802.stderr
@@ -0,0 +1,9 @@
error[E0590]: `break` or `continue` with no label in the condition of a `while` loop
--> $DIR/issue-50802.rs:15:21
|
LL | break while continue { //~ ERROR E0590
| ^^^^^^^^ unlabeled `continue` in the condition of a `while` loop

error: aborting due to previous error

For more information about this error, try `rustc --explain E0590`.

0 comments on commit 5e30f6b

Please sign in to comment.