diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 2368b1aca6948..ac37937509eac 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -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 diff --git a/src/test/ui/issue-50802.rs b/src/test/ui/issue-50802.rs new file mode 100644 index 0000000000000..6342d0757ee53 --- /dev/null +++ b/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 or the MIT license +// , 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 + } + } +} diff --git a/src/test/ui/issue-50802.stderr b/src/test/ui/issue-50802.stderr new file mode 100644 index 0000000000000..9da2648b376f7 --- /dev/null +++ b/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`.