2021-06-14 10:15:05 +00:00
|
|
|
use crate::{Diagnostic, DiagnosticsContext};
|
2021-06-13 16:51:19 +00:00
|
|
|
|
|
|
|
// Diagnostic: break-outside-of-loop
|
|
|
|
//
|
|
|
|
// This diagnostic is triggered if the `break` keyword is used outside of a loop.
|
2021-06-14 16:32:39 +00:00
|
|
|
pub(crate) fn break_outside_of_loop(
|
2021-06-13 16:51:19 +00:00
|
|
|
ctx: &DiagnosticsContext<'_>,
|
|
|
|
d: &hir::BreakOutsideOfLoop,
|
|
|
|
) -> Diagnostic {
|
|
|
|
Diagnostic::new(
|
|
|
|
"break-outside-of-loop",
|
|
|
|
"break outside of loop",
|
|
|
|
ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-06-14 10:15:05 +00:00
|
|
|
use crate::tests::check_diagnostics;
|
2021-06-13 16:51:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn break_outside_of_loop() {
|
|
|
|
check_diagnostics(
|
|
|
|
r#"
|
|
|
|
fn foo() { break; }
|
2021-06-14 19:06:28 +00:00
|
|
|
//^^^^^ error: break outside of loop
|
2021-06-13 16:51:19 +00:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|