Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs')
-rw-r--r--crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
index 10e637979f..114face2dc 100644
--- a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
+++ b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
@@ -7,10 +7,15 @@ pub(crate) fn break_outside_of_loop(
ctx: &DiagnosticsContext<'_>,
d: &hir::BreakOutsideOfLoop,
) -> Diagnostic {
- let construct = if d.is_break { "break" } else { "continue" };
+ let message = if d.bad_value_break {
+ "can't break with a value in this position".to_owned()
+ } else {
+ let construct = if d.is_break { "break" } else { "continue" };
+ format!("{construct} outside of loop")
+ };
Diagnostic::new(
"break-outside-of-loop",
- format!("{construct} outside of loop"),
+ message,
ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range,
)
}
@@ -135,4 +140,18 @@ fn foo() {
"#,
);
}
+
+ #[test]
+ fn value_break_in_for_loop() {
+ check_diagnostics(
+ r#"
+fn test() {
+ for _ in [()] {
+ break 3;
+ // ^^^^^^^ error: can't break with a value in this position
+ }
+}
+"#,
+ );
+ }
}