denoland/deno · error · syn::Error
Structs do not support enum converters
Error message
Structs do not support enum converters
What it means
In libs/ops/webidl/mod.rs the converter kind must match the item kind: `webidl(dictionary)` is only implemented for `Data::Struct`. If a struct carries `#[webidl(enum)]`, the mismatch is reported with this error on the struct's span.
Source
Thrown at libs/ops/webidl/mod.rs:38
let input = parse2::<DeriveInput>(item)?;
let span = input.span();
let ident = input.ident;
let ident_string = ident.to_string();
let converter = input
.attrs
.into_iter()
.find_map(|attr| ConverterType::from_attribute(attr).transpose())
.ok_or_else(|| {
Error::new(span, "missing top-level #[webidl] attribute")
})??;
let out = match input.data {
Data::Struct(data) => match converter {
ConverterType::Dictionary => {
create_impl(ident, dictionary::get_body(ident_string, span, data)?)
}
ConverterType::Enum => {
return Err(Error::new(span, "Structs do not support enum converters"));
}
},
Data::Enum(data) => match converter {
ConverterType::Dictionary => {
return Err(Error::new(
span,
"Enums currently do not support dictionary converters",
));
}
ConverterType::Enum => {
let (body, as_str) = r#enum::get_body(ident_string, &ident, data)?;
let implementation = create_impl(ident, body);
quote! {
#implementation
#as_str
}
}View on GitHub (pinned to 9ad36f7a2c)
Solutions
- If the type is a struct of named members, use `#[webidl(dictionary)]`.
- If the type should be a WebIDL enum, declare it as a Rust `enum` with unit variants and keep `#[webidl(enum)]`.
Example fix
// before
#[derive(WebIDL)]
#[webidl(enum)]
struct ColorMode { pub value: String }
// after
#[derive(WebIDL)]
#[webidl(dictionary)]
struct ColorMode { pub value: String } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time: `cargo check`. Pairing rule: // struct -> #[webidl(dictionary)] // enum -> #[webidl(enum)]
Prevention
- When changing an item between struct and enum, update the webidl converter attribute in the same commit.
- Avoid copy-pasting webidl attributes across items of different kinds.
When it happens
Trigger: `#[webidl(enum)] struct Color { ... }` — annotating a struct with the enum converter.
Common situations: Copy-pasting an enum's attributes onto a struct; changing an enum into a struct (or vice versa) during refactoring without updating the webidl attribute.
Related errors
- Enums currently do not support dictionary converters
- Unnamed fields are currently not supported
- Unit fields are currently not supported
- variants with fields are not allowed for enum converters
- missing top-level #[webidl] attribute
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/7dd55acd853cbfc1.
Report an issue: GitHub.