swc-project/swc · error
union
Error message
union
What it means
`#[derive(EqIgnoreSpan)]` generates span-insensitive equality for structs and enums by emitting one match arm per variant. `Data::Union(_) => unimplemented!("union")` — deriving it on a Rust union panics at compile time because there is no union strategy yet.
Source
Thrown at crates/swc_eq_ignore_macros/src/lib.rs:98
let arm = self.make_arm_from_fields(parse_quote!(Self), &s.fields);
parse_quote!(match (self, other) { #arm })
}
Data::Enum(e) => {
//
let mut arms = Punctuated::<_, Token![,]>::default();
for v in &e.variants {
let vi = &v.ident;
let arm = self.make_arm_from_fields(parse_quote!(Self::#vi), &v.fields);
arms.push(arm);
}
arms.push(parse_quote!(_ => false));
parse_quote!(match (self, other) { #arms })
}
Data::Union(_) => unimplemented!("union"),
}
}
fn make_arm_from_fields(&self, pat_path: Path, fields: &Fields) -> Arm {
let mut l_pat_fields = Punctuated::<_, Token![,]>::default();
let mut r_pat_fields = Punctuated::<_, Token![,]>::default();
let mut exprs = Vec::new();
for (i, field) in fields
.iter()
.enumerate()
.filter(|(_, f)| !(self.ignore_field)(f))
{
let method_name =
if field.attrs.iter().any(|attr| {
attr.path().is_ident("not_spanned") || attr.path().is_ident("use_eq")
}) {
Ident::new("eq", Span::call_site())View on GitHub (pinned to d7d7434666)
Solutions
- Wrap the union in a struct, derive on the struct, and hand-write an EqIgnoreSpan impl comparing the raw bytes/fields
- Convert the union to a struct if the union layout is not required
- Contribute a `Data::Union` arm upstream
Example fix
// before
#[derive(EqIgnoreSpan)]
union U { a: u32, b: f32 }
// after
#[derive(EqIgnoreSpan)]
struct U { bits: u32 } // compare via bits; or impl manually Defensive patterns
Strategy: validation
Prevention
- Never place #[derive(EqIgnoreSpan)] on a union; wrap or convert instead
- When applying derives via shared macro lists, exclude unions explicitly
When it happens
Trigger: Write `#[derive(EqIgnoreSpan)] union MyUnion { a: u32, b: f32 }` in a crate that depends on swc_eq_ignore_macros.
Common situations: AST-like crates modeling bitsets or byte layouts as unions; derive lists applied broadly via macros or templates; internal swc work adding unions to AST types.
Related errors
- generic parameter other than type
- Box() -> T or Box without a type parameter
- Fast-path injection for Fold / VisitMut where pattern is not
- Unknown visitor type: {:?}
- derive(Merge) does not support an enum
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/e6f5a9238c186f41.
Report an issue: GitHub.