diff options
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.rs | 30 |
1 files changed, 30 insertions, 0 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 new file mode 100644 index 000000000..5ad0fbd1b --- /dev/null +++ b/crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs | |||
@@ -0,0 +1,30 @@ | |||
1 | use crate::{Diagnostic, DiagnosticsContext}; | ||
2 | |||
3 | // Diagnostic: break-outside-of-loop | ||
4 | // | ||
5 | // This diagnostic is triggered if the `break` keyword is used outside of a loop. | ||
6 | pub(crate) fn break_outside_of_loop( | ||
7 | ctx: &DiagnosticsContext<'_>, | ||
8 | d: &hir::BreakOutsideOfLoop, | ||
9 | ) -> Diagnostic { | ||
10 | Diagnostic::new( | ||
11 | "break-outside-of-loop", | ||
12 | "break outside of loop", | ||
13 | ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range, | ||
14 | ) | ||
15 | } | ||
16 | |||
17 | #[cfg(test)] | ||
18 | mod tests { | ||
19 | use crate::tests::check_diagnostics; | ||
20 | |||
21 | #[test] | ||
22 | fn break_outside_of_loop() { | ||
23 | check_diagnostics( | ||
24 | r#" | ||
25 | fn foo() { break; } | ||
26 | //^^^^^ break outside of loop | ||
27 | "#, | ||
28 | ); | ||
29 | } | ||
30 | } | ||