denoland/deno · error · syn::Error
cppgc inheritance requires #[repr(C)] on the type
Error message
cppgc inheritance requires #[repr(C)] on the type
What it means
The CppgcInherits derive emits compile-time offset assertions that rely on a stable C layout, so the target type must be #[repr(C)]. ensure_repr_c scans the type's attributes and only accepts a bare #[repr(C)] or a repr list containing C (e.g. #[repr(C, packed)]); anything else — no repr, #[repr(u8)], #[repr(Rust)] — yields this compile error.
Source
Thrown at libs/ops/cppgc.rs:161
}
fn ensure_repr_c(attrs: &[Attribute], span: proc_macro2::Span) -> Result<()> {
for attr in attrs {
if !attr.path().is_ident("repr") {
continue;
}
if let Meta::List(list) = &attr.meta {
let nested: Punctuated<Meta, Token![,]> =
list.parse_args_with(Punctuated::parse_terminated)?;
if nested
.iter()
.any(|meta| matches!(meta, Meta::Path(path) if path.is_ident("C")))
{
return Ok(());
}
}
}
Err(Error::new(
span,
"cppgc inheritance requires #[repr(C)] on the type",
))
}
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>()?;View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Add #[repr(C)] directly above the struct: #[derive(CppgcInherits)] #[cppgc_inherits_from(Base)] #[repr(C)] struct Derived { base: Base, ... }.
- In multi-level chains, verify every type in the chain (base and derived) carries #[repr(C)], as the offset assertions walk the whole chain.
Example fix
// before
#[derive(CppgcInherits)]
#[cppgc_inherits_from(Shape)]
pub struct Rectangle { // error: cppgc inheritance requires #[repr(C)] on the type
base: Shape,
}
// after
#[derive(CppgcInherits)]
#[cppgc_inherits_from(Shape)]
#[repr(C)]
pub struct Rectangle {
base: Shape,
} Defensive patterns
Strategy: validation
Prevention
- Add #[repr(C)] at the moment you add #[derive(CppgcInherits)], not later — the layout is load-bearing for the offset assertions.
- In multi-level inheritance chains, check every type (base, intermediates, derived) carries #[repr(C)].
When it happens
Trigger: Declaring a derived cppgc class without a repr attribute, or with a non-C repr like #[repr(u8)] or #[repr(transparent)], under #[derive(CppgcInherits)] #[cppgc_inherits_from(...)].
Common situations: Converting an existing repr-Rust struct into a cppgc base/derived class and forgetting the layout attribute; enum-like reprs copy-pasted onto the struct; multi-level inheritance where an intermediate type was never marked.
Related errors
- cppgc inheritance requires at least one field
- first field must be the base type for cppgc inheritance
- FromV8 enum derive currently supports only unit and single-e
- Unions are not supported
- Unit fields are currently not supported
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/a59514ff136aac74.
Report an issue: GitHub.