Rollup merge of #50829 - est31:master, r=estebank
CheckLoopVisitor: also visit break expressions Fixes #50802
This commit is contained in:
commit
611dafcf06
@ -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
|
||||
|
18
src/test/ui/issue-50802.rs
Normal file
18
src/test/ui/issue-50802.rs
Normal file
@ -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
src/test/ui/issue-50802.stderr
Normal file
9
src/test/ui/issue-50802.stderr
Normal file
@ -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`.
|
Loading…
x
Reference in New Issue
Block a user