denoland/deno · error · syn::Error

derive(CppgcInherits) requires #[cppgc_inherits_from(BaseTyp

Error message

derive(CppgcInherits) requires #[cppgc_inherits_from(BaseType)]

What it means

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.

Source

Thrown at libs/ops/cppgc.rs:183

}

fn parse_base_attr(attrs: &[Attribute]) -> Result<Type> {
  let mut found = None;
  for attr in attrs {
    if !attr.path().is_ident("cppgc_inherits_from") {
      continue;
    }
    if found.is_some() {
      return Err(Error::new(
        attr.span(),
        "cppgc_inherits_from specified more than once",
      ));
    }
    let base = attr.parse_args::<Type>()?;
    found = Some(base);
  }
  found.ok_or_else(|| {
    Error::new(
      proc_macro2::Span::call_site(),
      "derive(CppgcInherits) requires #[cppgc_inherits_from(BaseType)]",
    )
  })
}

#[derive(Clone)]
enum FieldRef {
  Named(Ident, proc_macro2::Span),
  Unnamed(syn::Index, proc_macro2::Span),
}

fn first_field(data: &Data) -> Option<FieldRefWithType> {
  match data {
    Data::Struct(data_struct) => match &data_struct.fields {
      Fields::Named(fields) => fields.named.first().map(|f| FieldRefWithType {
        field: FieldRef::Named(f.ident.clone().unwrap(), f.ty.span()),
        ty: f.ty.clone(),

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Add the required helper attribute directly above the struct: `#[cppgc_inherits_from(BaseType)]`, where BaseType is the direct base that also derives `CppgcBase`.
  2. Check the spelling: the macro matches the exact identifier `cppgc_inherits_from`; `cppgc_inherit_from` or `cppgc::inherits_from` will not match.
  3. If the type has no base class, you probably want `#[derive(CppgcBase)]` alone instead of `CppgcInherits`.

Example fix

// before
#[derive(CppgcInherits, CppgcBase)]
struct DOMPoint { base: DOMPointReadOnly }

// after
#[derive(CppgcInherits, CppgcBase)]
#[cppgc_inherits_from(DOMPointReadOnly)]
struct DOMPoint { base: DOMPointReadOnly }
Defensive patterns

Strategy: validation

Validate before calling

// Quick check: any `derive(CppgcInherits)` type must have a matching helper attribute.
// Run `cargo check` — this error is fully deterministic at compile time.

Prevention

When it happens

Trigger: `#[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.

Common situations: Adding `derive(CppgcInherits)` from an editor auto-complete without the helper attribute; typos in the attribute path; refactoring that accidentally drops the attribute.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/79da8dca8f3e4a65. Report an issue: GitHub.