Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/union_pat_has_rest.rs')
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/union_pat_has_rest.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/ide-diagnostics/src/handlers/union_pat_has_rest.rs b/crates/ide-diagnostics/src/handlers/union_pat_has_rest.rs new file mode 100644 index 0000000000..9333118719 --- /dev/null +++ b/crates/ide-diagnostics/src/handlers/union_pat_has_rest.rs @@ -0,0 +1,41 @@ +use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext}; + +// Diagnostic: union-pat-has-rest +// +// A union pattern uses `..`. +pub(crate) fn union_pat_has_rest( + ctx: &DiagnosticsContext<'_, '_>, + d: &hir::UnionPatHasRest, +) -> Diagnostic { + Diagnostic::new_with_syntax_node_ptr( + ctx, + DiagnosticCode::RustcHardError("E0784"), + "union patterns cannot use `..`", + d.pat.map(Into::into), + ) + .stable() +} + +#[cfg(test)] +mod tests { + use crate::tests::check_diagnostics; + + #[test] + fn union_pat_has_rest() { + check_diagnostics( + r#" +union Bird { + pigeon: u8, + turtledove: u16, +} + +fn main(bird: Bird) { + unsafe { + let Bird { pigeon: 0, .. } = bird; + //^^^^^^^^^^^^^^^^^^^^^^ error: union patterns cannot use `..` + } +} +"#, + ); + } +} |