about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-05-19 23:41:01 +0800
committerkennytm <kennytm@gmail.com>2018-05-20 04:16:03 +0800
commit611dafcf061538e9ab3bb0ac00c18a27ffb6bdb9 (patch)
tree736210e3e48ae1c76aa442da338fdd59c7940a87
parentfbfce83f5848964fcc71e00ccc574c0b6cfd7577 (diff)
parent5e30f6b916826bd8491ad0e115e194e6a935b58c (diff)
downloadrust-611dafcf061538e9ab3bb0ac00c18a27ffb6bdb9.tar.gz
rust-611dafcf061538e9ab3bb0ac00c18a27ffb6bdb9.zip
Rollup merge of #50829 - est31:master, r=estebank
CheckLoopVisitor: also visit break expressions

Fixes #50802
-rw-r--r--src/librustc_passes/loops.rs2
-rw-r--r--src/test/ui/issue-50802.rs18
-rw-r--r--src/test/ui/issue-50802.stderr9
3 files changed, 29 insertions, 0 deletions
diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs
index 2368b1aca69..ac37937509e 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 00000000000..6342d0757ee
--- /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 00000000000..9da2648b376
--- /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`.