{"record":{"id":"79da8dca8f3e4a65","repo":"denoland/deno","slug":"derive-cppgcinherits-requires-cppgc-inherits-fr","errorCode":null,"errorMessage":"derive(CppgcInherits) requires #[cppgc_inherits_from(BaseType)]","messagePattern":"derive\\(CppgcInherits\\) requires #\\[cppgc_inherits_from\\(BaseType\\)\\]","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/cppgc.rs","lineNumber":183,"sourceCode":"}\n\nfn parse_base_attr(attrs: &[Attribute]) -> Result<Type> {\n  let mut found = None;\n  for attr in attrs {\n    if !attr.path().is_ident(\"cppgc_inherits_from\") {\n      continue;\n    }\n    if found.is_some() {\n      return Err(Error::new(\n        attr.span(),\n        \"cppgc_inherits_from specified more than once\",\n      ));\n    }\n    let base = attr.parse_args::<Type>()?;\n    found = Some(base);\n  }\n  found.ok_or_else(|| {\n    Error::new(\n      proc_macro2::Span::call_site(),\n      \"derive(CppgcInherits) requires #[cppgc_inherits_from(BaseType)]\",\n    )\n  })\n}\n\n#[derive(Clone)]\nenum FieldRef {\n  Named(Ident, proc_macro2::Span),\n  Unnamed(syn::Index, proc_macro2::Span),\n}\n\nfn first_field(data: &Data) -> Option<FieldRefWithType> {\n  match data {\n    Data::Struct(data_struct) => match &data_struct.fields {\n      Fields::Named(fields) => fields.named.first().map(|f| FieldRefWithType {\n        field: FieldRef::Named(f.ident.clone().unwrap(), f.ty.span()),\n        ty: f.ty.clone(),","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/cppgc.rs#L165-L201","documentation":"Thrown by the `CppgcInherits` derive macro when `parse_base_attr` finds no `#[cppgc_inherits_from(...)]` helper attribute at all. The derive needs the base type to generate the upcast/inheritance glue, so it returns this error at the call-site span (`proc_macro2::Span::call_site()`) telling you the required attribute shape.","triggerScenarios":"`#[derive(CppgcInherits)]` on a struct (or enum) with no `#[cppgc_inherits_from(BaseType)]` attribute next to it; also when the attribute name is misspelled (e.g. `#[cppgc_inherit_from(...)]`), because the misspelled version is silently skipped by the `is_ident` check.","commonSituations":"Adding `derive(CppgcInherits)` from an editor auto-complete without the helper attribute; typos in the attribute path; refactoring that accidentally drops the attribute.","solutions":["Add the required helper attribute directly above the struct: `#[cppgc_inherits_from(BaseType)]`, where BaseType is the direct base that also derives `CppgcBase`.","Check the spelling: the macro matches the exact identifier `cppgc_inherits_from`; `cppgc_inherit_from` or `cppgc::inherits_from` will not match.","If the type has no base class, you probably want `#[derive(CppgcBase)]` alone instead of `CppgcInherits`."],"exampleFix":"// before\n#[derive(CppgcInherits, CppgcBase)]\nstruct DOMPoint { base: DOMPointReadOnly }\n\n// after\n#[derive(CppgcInherits, CppgcBase)]\n#[cppgc_inherits_from(DOMPointReadOnly)]\nstruct DOMPoint { base: DOMPointReadOnly }","handlingStrategy":"validation","validationCode":"// Quick check: any `derive(CppgcInherits)` type must have a matching helper attribute.\n// Run `cargo check` — this error is fully deterministic at compile time.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write the attribute pair together: `#[cppgc_inherits_from(Base)]` directly above `#[derive(CppgcInherits, CppgcBase)]`.","Use a snippet/template for cppgc types so the helper attribute is never forgotten."],"tags":["cppgc","proc-macro","derive-macro","missing-attribute","compile-time"],"backgroundTag":"missing-macro-attribute","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}