Skip to content

Commit 5e30f6b

Browse files
committed
CheckLoopVisitor: also visit break expressions
Fixes rust-lang#50802
1 parent 0e325d0 commit 5e30f6b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/librustc_passes/loops.rs

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
8989
self.with_context(LabeledBlock, |v| v.visit_block(&b));
9090
}
9191
hir::ExprBreak(label, ref opt_expr) => {
92+
opt_expr.as_ref().map(|e| self.visit_expr(e));
93+
9294
if self.require_label_in_labeled_block(e.span, &label, "break") {
9395
// If we emitted an error about an unlabeled break in a labeled
9496
// block, we don't need any further checking for this break any more

src/test/ui/issue-50802.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[allow(unreachable_code)]
12+
13+
fn main() {
14+
loop {
15+
break while continue { //~ ERROR E0590
16+
}
17+
}
18+
}

src/test/ui/issue-50802.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0590]: `break` or `continue` with no label in the condition of a `while` loop
2+
--> $DIR/issue-50802.rs:15:21
3+
|
4+
LL | break while continue { //~ ERROR E0590
5+
| ^^^^^^^^ unlabeled `continue` in the condition of a `while` loop
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0590`.

0 commit comments

Comments
 (0)