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

  1. If the type is a struct of named members, use `#[webidl(dictionary)]`.
  2. 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 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


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