diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-13 18:07:04 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-13 18:07:04 +0100 |
commit | 60ca03e8aa00956d1511969da5f1844a02483bc9 (patch) | |
tree | 7729eb4ae1ef7a4cf0e0be42dfc2ef36c65cec1e /crates/ide/src/diagnostics/break_outside_of_loop.rs | |
parent | 8e5f469da8d5ed0e4c0519c883498097aeadd7ac (diff) | |
parent | 8d391ec981562785ec92ce3afe950972c523f925 (diff) |
Merge #9252
9252: internal: refactor mismatched args count diagnostic r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src/diagnostics/break_outside_of_loop.rs')
-rw-r--r-- | crates/ide/src/diagnostics/break_outside_of_loop.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ide/src/diagnostics/break_outside_of_loop.rs b/crates/ide/src/diagnostics/break_outside_of_loop.rs new file mode 100644 index 000000000..80e68f3cc --- /dev/null +++ b/crates/ide/src/diagnostics/break_outside_of_loop.rs | |||
@@ -0,0 +1,30 @@ | |||
1 | use crate::diagnostics::{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(super) 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::diagnostics::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 | } | ||