about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2021-01-21 18:13:05 -0800
committerEsteban Küber <esteban@kuber.com.ar>2021-01-21 21:43:29 -0800
commit9e82329c8f621e59833f4e2d747acdd83b188054 (patch)
tree049d4c96179a887e3120369eb5d67ba357a31200 /compiler/rustc_passes/src
parent76988077700f222791c480e811a709766b099875 (diff)
downloadrust-9e82329c8f621e59833f4e2d747acdd83b188054.tar.gz
rust-9e82329c8f621e59833f4e2d747acdd83b188054.zip
Do not suggest using a break label when one is already present
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/loops.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/compiler/rustc_passes/src/loops.rs b/compiler/rustc_passes/src/loops.rs
index 18b6b98e16a..4bfac1b7298 100644
--- a/compiler/rustc_passes/src/loops.rs
+++ b/compiler/rustc_passes/src/loops.rs
@@ -68,18 +68,18 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
             hir::ExprKind::Block(ref b, Some(_label)) => {
                 self.with_context(LabeledBlock, |v| v.visit_block(&b));
             }
-            hir::ExprKind::Break(label, ref opt_expr) => {
+            hir::ExprKind::Break(break_label, ref opt_expr) => {
                 if let Some(e) = opt_expr {
                     self.visit_expr(e);
                 }
 
-                if self.require_label_in_labeled_block(e.span, &label, "break") {
+                if self.require_label_in_labeled_block(e.span, &break_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
                     return;
                 }
 
-                let loop_id = match label.target_id {
+                let loop_id = match break_label.target_id {
                     Ok(loop_id) => Some(loop_id),
                     Err(hir::LoopIdError::OutsideLoopScope) => None,
                     Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
@@ -94,7 +94,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
                 }
 
                 if let Some(break_expr) = opt_expr {
-                    let (head, label, loop_kind) = if let Some(loop_id) = loop_id {
+                    let (head, loop_label, loop_kind) = if let Some(loop_id) = loop_id {
                         match self.hir_map.expect_expr(loop_id).kind {
                             hir::ExprKind::Loop(_, label, source, sp) => {
                                 (Some(sp), label, Some(source))
@@ -135,10 +135,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
                                     "use `break` on its own without a value inside this `{}` loop",
                                     kind.name(),
                                 ),
-                                "break".to_string(),
+                                format!(
+                                    "break{}",
+                                    break_label
+                                        .label
+                                        .map_or_else(String::new, |l| format!(" {}", l.ident))
+                                ),
                                 Applicability::MaybeIncorrect,
                             );
-                            if let Some(label) = label {
+                            if let (Some(label), None) = (loop_label, break_label.label) {
                                 match break_expr.kind {
                                     hir::ExprKind::Path(hir::QPath::Resolved(
                                         None,