tracel-ai/burn · error

Field {} as no generic

Error message

Field {} as no generic

What it means

Type-shape guard in the derive field helper: `first_generic_field` assumes the field's type is a generic path (e.g. `Linear<B>`) and panics with the field's name when the type path has no generic arguments (or the type is not a path at all, like a primitive). It fires at macro expansion when codegen expects a generic parameter that the field type does not provide; the input at fault is the non-generic field type.

Source

Thrown at crates/burn-derive/src/shared/field.rs:31

    }

    pub fn ident(&self) -> Ident {
        self.field.ident.clone().unwrap()
    }

    pub fn is_of_type(&self, paths: &[&str]) -> bool {
        match &self.field.ty {
            syn::Type::Path(path) => {
                let name = Self::path_name(path);
                paths.contains(&name.as_str())
            }
            _ => false,
        }
    }

    #[allow(dead_code)]
    pub fn first_generic_field(&self) -> TypePath {
        let err = || panic!("Field {} as no generic", self.field.ident.clone().unwrap());
        match &self.field.ty {
            syn::Type::Path(path) => Self::path_generic_argument(path),
            _ => err(),
        }
    }
    pub fn path_generic_argument(path: &TypePath) -> TypePath {
        let segment = path.path.segments.last().unwrap();
        let err = || panic!("Path segment {} has no generic", segment.ident.clone(),);
        match &segment.arguments {
            syn::PathArguments::None => err(),
            syn::PathArguments::AngleBracketed(param) => {
                let first_param = param.args.first().unwrap();

                if let syn::GenericArgument::Type(Type::Path(path)) = first_param {
                    path.clone()
                } else {
                    err()
                }

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Make the field type generic (e.g. `Param<Tensor<B, D>>` instead of a concrete type) so codegen can extract the backend generic.
  2. If the field should not carry generics, avoid the code path calling `first_generic_field` for it (annotate with the appropriate skip/ignore attribute).
  3. Check for typos that make the intended generic type resolve to a plain path.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/burn-derive/src/shared/field.rs:31 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/512c1f5455929da5. Report an issue: GitHub.