tracel-ai/burn · error
Path segment {} has no generic
Error message
Path segment {} has no generic What it means
Segment-level guard in the same helper: `path_generic_argument` takes the last path segment and panics with the segment name when that segment has no generic arguments (e.g. field type `Tensor` without `<B, D>`, or a segment like `Vec` accessed mid-path). It reports derive-codegen expectations versus the actual written type; the input at fault is the generic-less path segment.
Source
Thrown at crates/burn-derive/src/shared/field.rs:39
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()
}
}
syn::PathArguments::Parenthesized(_) => err(),
}
}
fn path_name(path: &TypePath) -> String {
let length = path.path.segments.len();
let mut name = String::new();View on GitHub (pinned to d16f7ba2ed)
Solutions
- Add the expected generic parameters to the field type (e.g. `MyType<B>` rather than `MyType`).
- Verify the codegen path targets the correct segment — fully qualify the type so the generic segment is analyzed.
- Use the appropriate module attribute to skip fields that legitimately have no generics.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/burn-derive/src/shared/field.rs:39 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/a1332c2b67dbcbd0.
Report an issue: GitHub.