swc-project/swc · error

Unknown span attribute

Error message

Unknown span attribute

What it means

Compile-time panic from the Spanned derive support code (crates/ast_node/src/spanned.rs). A `#[span]` attribute must be either a bare path (`#[span]`) or a parenthesized list (`#[span(lo)]`/`#[span(hi)]`); the Meta::NameValue form (e.g. `#[span = "lo"]`) falls into the catch-all arm and panics with the argument-less message.

Source

Thrown at crates/ast_node/src/spanned.rs:71

            }

            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)
        .variants()
        .into_iter()
        .map(|v| {
            let (pat, bindings) = v.bind("_", Some(Token![ref](def_site())), None);

View on GitHub (pinned to 5176682b65)

Solutions

  1. Change the name-value form to list form: `#[span(lo)]` or `#[span(hi)]`
  2. Use bare `#[span]` if the whole field is the span source

Example fix

// before
#[span = "lo"]
pub start: Ident,

// after
#[span(lo)]
pub start: Ident,
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Writing `#[span = "lo"]` or any `key = value` form of the span attribute on a field of a Spanned-deriving type.

Common situations: Editors auto-completing attributes into name-value syntax; converting attribute styles during refactors.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/b0191c7ec4ebfdb7. Report an issue: GitHub.