Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/yield_outside_coroutine.rs')
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/yield_outside_coroutine.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/yield_outside_coroutine.rs b/crates/ide-diagnostics/src/handlers/yield_outside_coroutine.rs new file mode 100644 index 0000000000..39288c2817 --- /dev/null +++ b/crates/ide-diagnostics/src/handlers/yield_outside_coroutine.rs @@ -0,0 +1,34 @@ +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext}; + +// Diagnostic: yield-outside-of-coroutine +// +// This diagnostic is triggered if the `yield` keyword is used outside of a coroutine. +pub(crate) fn yield_outside_coroutine( + ctx: &DiagnosticsContext<'_, '_>, + d: &hir::YieldOutsideCoroutine, +) -> Diagnostic { + Diagnostic::new_with_syntax_node_ptr( + ctx, + DiagnosticCode::RustcHardError("E0627"), + "yield expression outside of coroutine", + d.expr.map(|it| it.into()), + ) +} + +#[cfg(test)] +mod tests { + use crate::tests::check_diagnostics; + + #[test] + fn yield_in_regular_function() { + check_diagnostics( + r#" +//- minicore: coroutine +fn foo() { + yield 1; + //^^^^^^^ error: yield expression outside of coroutine +} +"#, + ); + } +} |