aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-14 17:32:39 +0100
committerAleksey Kladov <[email protected]>2021-06-14 17:45:39 +0100
commit4768e5fb23c058eba90f0a1dcd6e9d5c0ecdee1b (patch)
tree814f6a8ace5d131b9f704b3f81e8287b36943b79 /crates/ide_diagnostics/src/handlers/break_outside_of_loop.rs
parent94f7b63522cb7464a853c74a8431587db6434b12 (diff)
internal: document diagnostics crate
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.rs30
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 @@
1use 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.
6pub(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)]
18mod tests {
19 use crate::tests::check_diagnostics;
20
21 #[test]
22 fn break_outside_of_loop() {
23 check_diagnostics(
24 r#"
25fn foo() { break; }
26 //^^^^^ break outside of loop
27"#,
28 );
29 }
30}