swc-project/swc · error
Unknown span attribute: {kind:?}
Error message
Unknown span attribute: {kind:?} What it means
Compile-time panic from the Spanned derive support code (crates/ast_node/src/spanned.rs). Inside a `#[span(...)]` field attribute, the macro parses a comma-separated ident list (`InputFieldAttr`) and only `lo` and `hi` are valid kinds; any other ident panics with `Unknown span attribute: {kind:?}`.
Source
Thrown at crates/ast_node/src/spanned.rs:67
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(),
lo,
hi,
}
}
}
pub fn derive(input: DeriveInput) -> ItemImpl {
let arms = Binder::new_from(&input)View on GitHub (pinned to 5176682b65)
Solutions
- Correct the attribute to exactly `#[span(lo)]` or `#[span(hi)]`
- Mark one field `#[span(lo)]` and another `#[span(hi)]` to compose a span from both ends
Example fix
// before
struct Bin {
#[span(low)]
pub left: Expr,
}
// after
struct Bin {
#[span(lo)]
pub left: Expr,
} Defensive patterns
Strategy: validation
Prevention
- Use only `lo` and `hi` inside `#[span(...)]`
- Pair each `#[span(lo)]` with a `#[span(hi)]` on another field from the start
When it happens
Trigger: Writing `#[span(low)]`, `#[span(lho)]`, or `#[span(lo, whole)]` on a field of a type deriving Spanned.
Common situations: Typos in span markers while porting AST node definitions; assuming extra span kinds (e.g. `both`, `full`) exist because `lo`/`hi` do.
Related errors
- Unknown span attribute
- #[derive(Spanned)] requires a field to get span from
- #[derive(Spanned)]: cannot determine span field to use for {
- #[derive(Spanned)]: #[span(lo)] and #[span(hi)] is required
- An element descriptor's .kind property must be either "metho
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/5e0e25f3538b05c4.
Report an issue: GitHub.