swc-project/swc · error

derive(Merge) does not support a unit struct

Error message

derive(Merge) does not support a unit struct

What it means

A derive-macro validation abort in call_merge_for_fields (swc_config_macro merge.rs:51). The helper generates merge calls for named, unnamed, and no-field cases; when the Fields value is a unit struct (Fields::Unit), there are no fields to merge and the codegen path panics with 'derive(Merge) does not support a unit struct'. The unit struct annotated with #[derive(Merge)] is the input at fault.

Solutions

  1. Add meaningful fields to the struct, or drop the Merge derive if the type has nothing to merge
  2. Implement an empty merge body for Fields::Unit (it is trivially a no-op) and remove the panic
  3. Report the unsupported shape with a spanned compile_error! naming the struct
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_config_macro/src/merge.rs:51 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/cc447b4a35380277. Report an issue: GitHub.

Appendix: source

Thrown at crates/swc_config_macro/src/merge.rs:51

        parse_quote!(swc_config::merge::Merge::merge(&mut #l, #r))
    }

    match fields {
        Fields::Named(fs) => fs
            .named
            .iter()
            .enumerate()
            .map(|(idx, f)| call_merge(obj, idx, f))
            .map(|expr| Stmt::Expr(expr, Some(Token![;](fs.brace_token.span.join()))))
            .collect(),
        Fields::Unnamed(fs) => fs
            .unnamed
            .iter()
            .enumerate()
            .map(|(idx, f)| call_merge(obj, idx, f))
            .map(|expr| Stmt::Expr(expr, Some(Token![;](fs.paren_token.span.join()))))
            .collect(),
        Fields::Unit => unimplemented!("derive(Merge) does not support a unit struct"),
    }
}

View on GitHub (pinned to 5176682b65)