Diagnose incorrect continue expressions
This commit is contained in:
@@ -7,9 +7,10 @@ pub(crate) fn break_outside_of_loop(
|
||||
ctx: &DiagnosticsContext<'_>,
|
||||
d: &hir::BreakOutsideOfLoop,
|
||||
) -> Diagnostic {
|
||||
let construct = if d.is_break { "break" } else { "continue" };
|
||||
Diagnostic::new(
|
||||
"break-outside-of-loop",
|
||||
"break outside of loop",
|
||||
format!("{construct} outside of loop"),
|
||||
ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range,
|
||||
)
|
||||
}
|
||||
@@ -19,11 +20,19 @@ mod tests {
|
||||
use crate::tests::check_diagnostics;
|
||||
|
||||
#[test]
|
||||
fn break_outside_of_loop() {
|
||||
fn outside_of_loop() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
fn foo() { break; }
|
||||
//^^^^^ error: break outside of loop
|
||||
fn foo() {
|
||||
break;
|
||||
//^^^^^ error: break outside of loop
|
||||
break 'a;
|
||||
//^^^^^^^^ error: break outside of loop
|
||||
continue;
|
||||
//^^^^^^^^ error: continue outside of loop
|
||||
continue 'a;
|
||||
//^^^^^^^^^^^ error: continue outside of loop
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user