From 5e30f6b916826bd8491ad0e115e194e6a935b58c Mon Sep 17 00:00:00 2001 From: est31 <MTest31@outlook.com> Date: Thu, 17 May 2018 13:12:05 +0200 Subject: [PATCH] CheckLoopVisitor: also visit break expressions Fixes #50802 --- src/librustc_passes/loops.rs | 2 ++ src/test/ui/issue-50802.rs | 18 ++++++++++++++++++ src/test/ui/issue-50802.stderr | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/test/ui/issue-50802.rs create mode 100644 src/test/ui/issue-50802.stderr 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 <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 + } + } +} 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`.