diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index c23f28fe220..008c71cc9ce 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -119,6 +119,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { kind.name()) .span_label(e.span, "can only break with a value inside `loop`") + .span_suggestion(e.span, + &format!("instead, use `break` on its own \ + without a value inside this `{}` loop", + kind.name()), + "break".to_string()) .emit(); } } diff --git a/src/test/ui/loop-break-value-no-repeat.stderr b/src/test/ui/loop-break-value-no-repeat.stderr index 296b3b191e3..982de00b4fa 100644 --- a/src/test/ui/loop-break-value-no-repeat.stderr +++ b/src/test/ui/loop-break-value-no-repeat.stderr @@ -3,6 +3,10 @@ error[E0571]: `break` with value from a `for` loop | 22 | break 22 //~ ERROR `break` with value from a `for` loop | ^^^^^^^^ can only break with a value inside `loop` +help: instead, use `break` on its own without a value inside this `for` loop + | +22 | break //~ ERROR `break` with value from a `for` loop + | ^^^^^ error: aborting due to previous error