swc-project/swc · error

failed to parse input as DeriveInput

Error message

failed to parse input as DeriveInput

What it means

Proc-macro panic in derive_spanned: the input TokenStream did not parse as a syn DeriveInput (e.g. the derive was attached to something other than a struct/enum/union, or malformed tokens), so parse::<DeriveInput>().expect aborted expansion.

Source

Thrown at crates/ast_node/src/lib.rs:19

#![deny(clippy::all)]
#![recursion_limit = "1024"]

extern crate proc_macro;

use quote::quote;
use swc_macros_common::prelude::*;
use syn::*;

mod ast_node_macro;
mod encoding;
mod enum_deserialize;
mod spanned;

/// Derives [`swc_common::Spanned`]. See [`swc_common::Spanned`] for
/// documentation.
#[proc_macro_derive(Spanned, attributes(span))]
pub fn derive_spanned(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input = parse::<DeriveInput>(input).expect("failed to parse input as DeriveInput");

    let item = self::spanned::derive(input);

    print("derive(Spanned)", item.into_token_stream())
}

/// Derives `serde::Deserialize` which is aware of `tag` based deserialization.
#[proc_macro_derive(DeserializeEnum, attributes(tag, encoding))]
pub fn derive_deserialize_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input = parse::<DeriveInput>(input).expect("failed to parse input as DeriveInput");

    let item = enum_deserialize::expand(input);

    print("derive(DeserializeEnum)", item.into_token_stream())
}

#[proc_macro_derive(Encode, attributes(encoding))]
pub fn derive_encode(input: proc_macro::TokenStream) -> proc_macro::TokenStream {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Apply #[derive(Spanned)] only to plain structs, enums or unions
  2. Ensure no other attribute/macro mangles the item before the derive runs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ast_node/src/lib.rs:19 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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