swc-project/swc · error
failed to parse as `InputFieldAttr`
Error message
failed to parse as `InputFieldAttr`
What it means
Inside MyField::from_field, a #[span(...)] list attribute on a struct field failed to parse into InputFieldAttr. This fires at macro-expansion time when the span attribute's inner tokens are not the expected list of span kinds — e.g. #[span(foo)] with an unrecognized keyword or a malformed argument — while processing fields for the Spanned derive.
Source
Thrown at crates/ast_node/src/spanned.rs:59
is_unknown
})
}
impl MyField {
fn from_field(f: &Field) -> Self {
let mut lo = false;
let mut hi = false;
for attr in &f.attrs {
if !is_attr_name(attr, "span") {
continue;
}
match &attr.meta {
Meta::Path(..) => {}
Meta::List(list) => {
let input = parse2::<InputFieldAttr>(list.tokens.clone())
.expect("failed to parse as `InputFieldAttr`");
for kind in input.kinds {
if kind == "lo" {
lo = true
} else if kind == "hi" {
hi = true
} else {
panic!("Unknown span attribute: {kind:?}")
}
}
}
_ => panic!("Unknown span attribute"),
}
}
Self {
ident: f.ident.clone(),
ty: f.ty.clone(),View on GitHub (pinned to 5176682b65)
Solutions
- Use only the span kinds supported by the Spanned derive inside #[span(...)]
- Remove or fix malformed span attributes on the offending field
- Compare with existing fields in swc AST types for correct #[span] usage examples
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ast_node/src/spanned.rs:59 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/7ce9268916090dad.
Report an issue: GitHub.