]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / ide-diagnostics / src / handlers / break_outside_of_loop.rs
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 //^^^^^ error: break outside of loop
27 "#,
28 );
29 }
30 }