aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs12
-rw-r--r--crates/ide/src/diagnostics/break_outside_of_loop.rs30
2 files changed, 32 insertions, 10 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index caaa89e0a..e8f22c889 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -4,6 +4,7 @@
4//! macro-expanded files, but we need to present them to the users in terms of 4//! macro-expanded files, but we need to present them to the users in terms of
5//! original files. So we need to map the ranges. 5//! original files. So we need to map the ranges.
6 6
7mod break_outside_of_loop;
7mod inactive_code; 8mod inactive_code;
8mod macro_error; 9mod macro_error;
9mod missing_fields; 10mod missing_fields;
@@ -218,6 +219,7 @@ pub(crate) fn diagnostics(
218 for diag in diags { 219 for diag in diags {
219 #[rustfmt::skip] 220 #[rustfmt::skip]
220 let d = match diag { 221 let d = match diag {
222 AnyDiagnostic::BreakOutsideOfLoop(d) => break_outside_of_loop::break_outside_of_loop(&ctx, &d),
221 AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), 223 AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
222 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), 224 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
223 AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d), 225 AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d),
@@ -712,16 +714,6 @@ mod foo;
712 } 714 }
713 715
714 #[test] 716 #[test]
715 fn break_outside_of_loop() {
716 check_diagnostics(
717 r#"
718fn foo() { break; }
719 //^^^^^ break outside of loop
720"#,
721 );
722 }
723
724 #[test]
725 fn missing_unsafe_diagnostic_with_raw_ptr() { 717 fn missing_unsafe_diagnostic_with_raw_ptr() {
726 check_diagnostics( 718 check_diagnostics(
727 r#" 719 r#"
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 @@
1use 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.
6pub(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)]
18mod tests {
19 use crate::diagnostics::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}