swc-project/swc · error
derive(Merge) does not support an enum
Error message
derive(Merge) does not support an enum
What it means
A derive-macro validation abort in expand of swc_config_macro's Merge derive (merge.rs:22). The macro generates a merge implementation by iterating struct fields; when the DeriveInput's data is an Enum, there is no field-merging strategy to generate, so the expansion panics with 'derive(Merge) does not support an enum'. The enum type annotated with #[derive(Merge)] in user code is the input at fault.
Solutions
- Change the type to a struct so field-wise merging applies
- Implement per-variant merge semantics manually instead of deriving
- Emit a spanned compile_error! pointing at the enum definition instead of panicking
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_config_macro/src/merge.rs:22 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/db4d59354e59197f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/swc_config_macro/src/merge.rs:22
use syn::{parse_quote, DeriveInput, Expr, Field, Fields, Stmt, Token};
pub fn expand(input: DeriveInput) -> TokenStream {
match &input.data {
syn::Data::Struct(s) => {
let body = call_merge_for_fields("e!(self), &s.fields);
let body = join_stmts(&body);
let ident = &input.ident;
parse_quote!(
#[automatically_derived]
impl swc_config::merge::Merge for #ident {
fn merge(&mut self, _other: Self) {
#body
}
}
)
}
syn::Data::Enum(_) => unimplemented!("derive(Merge) does not support an enum"),
syn::Data::Union(_) => unimplemented!("derive(Merge) does not support a union"),
}
}
fn call_merge_for_fields(obj: &dyn ToTokens, fields: &Fields) -> Vec<Stmt> {
fn call_merge(obj: &dyn ToTokens, idx: usize, f: &Field) -> Expr {
let r = quote!(_other);
let l = access_field(obj, idx, f);
let r = access_field(&r, idx, f);
parse_quote!(swc_config::merge::Merge::merge(&mut #l, #r))
}
match fields {
Fields::Named(fs) => fs
.named
.iter()
.enumerate()View on GitHub (pinned to 5176682b65)