swc-project/swc · error

StringEnum requires all variants not to have fields

Error message

StringEnum requires all variants not to have fields

What it means

Raised in make_from_str during derive(StringEnum) (string_enum lib.rs:165). While processing each variant's attributes, the derive accepts only specific meta forms (the string tag and alias lists); any other attribute meta reached in the loop triggers 'Unsupported meta' and then this panic about variants requiring no fields. It fires when a variant carries data (non-unit variant) or an unrecognized attribute, either of which the string-enum codegen cannot handle. The variant's field list / stray attribute meta is the input at fault.

Source

Thrown at crates/string_enum/src/lib.rs:165

                            attrs: Default::default(),
                            lit: Lit::Str(item.alias),
                        }));
                    }

                    pat = Pat::Or(PatOr {
                        attrs: Default::default(),
                        leading_vert: None,
                        cases,
                    });
                    continue;
                }

                panic!("Unsupported meta: {:#?}", attr.meta);
            }

            let body = match *v.data() {
                Fields::Unit => Box::new(parse_quote!(return Ok(#qual_name))),
                _ => unreachable!("StringEnum requires all variants not to have fields"),
            };

            Arm {
                body,
                attrs: v
                    .attrs()
                    .iter()
                    .filter(|attr| is_attr_name(attr, "cfg"))
                    .cloned()
                    .collect(),
                pat,
                guard: None,
                fat_arrow_token: Default::default(),
                comma: Some(Token![,](def_site())),
            }
        })
        .chain(::std::iter::once(parse_quote!(_ => Err(()))))
        .collect();

View on GitHub (pinned to 5176682b65)

Solutions

  1. Make every variant of the StringEnum enum a unit variant (encode the string via the tag and aliases instead)
  2. Remove unsupported attributes from variants; only the documented tag/alias metas are accepted
  3. Report the unsupported meta with its span so the user can locate the bad attribute
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/string_enum/src/lib.rs:165 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/18d60a8600ee0b0c. Report an issue: GitHub.