ide_diagnostics/handlers/
union_expr_must_have_exactly_one_field.rs1use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
2
3pub(crate) fn union_expr_must_have_exactly_one_field(
7 ctx: &DiagnosticsContext<'_, '_>,
8 d: &hir::UnionExprMustHaveExactlyOneField,
9) -> Diagnostic {
10 Diagnostic::new_with_syntax_node_ptr(
11 ctx,
12 DiagnosticCode::RustcHardError("E0784"),
13 "union expressions should have exactly one field",
14 d.expr.map(|it| it.into()),
15 )
16 .stable()
17}
18
19#[cfg(test)]
20mod tests {
21 use crate::tests::check_diagnostics;
22
23 #[test]
24 fn union_expr_must_have_exactly_one_field() {
25 check_diagnostics(
26 r#"
27union Bird {
28 pigeon: u8,
29 turtledove: u16,
30}
31
32fn main() {
33 let bird = Bird { pigeon: 0 };
34 let bird = Bird {};
35 // ^^^^^^^ error: union expressions should have exactly one field
36 let bird = Bird { pigeon: 0, turtledove: 1 };
37 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: union expressions should have exactly one field
38}
39"#,
40 );
41 }
42}