denoland/deno · error · syn::Error

Unit fields are currently not supported

Error message

Unit fields are currently not supported

What it means

Same `get_body` match: a unit struct (`struct Foo;`) has no fields at all, so it cannot produce a WebIDL dictionary with members. The derive rejects `Fields::Unit` with this error on the struct's span.

Source

Thrown at libs/ops/webidl/dictionary.rs:39

use syn::spanned::Spanned;

use super::kw;

pub fn get_body(
  ident_string: String,
  span: Span,
  data: DataStruct,
) -> Result<TokenStream, Error> {
  let fields = match data.fields {
    Fields::Named(fields) => fields,
    Fields::Unnamed(_) => {
      return Err(Error::new(
        span,
        "Unnamed fields are currently not supported",
      ));
    }
    Fields::Unit => {
      return Err(Error::new(span, "Unit fields are currently not supported"));
    }
  };

  let mut fields = fields
    .named
    .into_iter()
    .map(TryInto::try_into)
    .collect::<Result<Vec<DictionaryField>, Error>>()?;
  fields.sort_by(|a, b| a.name.cmp(&b.name));

  let names = fields
    .iter()
    .map(|field| field.name.clone())
    .collect::<Vec<_>>();

  let fields = fields.into_iter().map(|field| {
    let field_name = field.name;
    let js_name = field.js_name.to_string();

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Give the struct named members, or if it is intentionally empty, drop the `#[derive(WebIDL)]` / `#[webidl(dictionary)]` attributes entirely.
  2. If an empty dictionary is genuinely required, add at least one named field (possibly `Option<T>` with an auto-None default) to satisfy the generator.

Example fix

// before
#[derive(WebIDL)]
#[webidl(dictionary)]
struct EmptyFlags;

// after
#[derive(WebIDL)]
#[webidl(dictionary)]
struct EmptyFlags { pub verbose: bool }
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: `cargo check`. Unit structs cannot be dictionaries;
// give the struct at least one named field or drop the derive.

Prevention

When it happens

Trigger: `#[derive(WebIDL)] #[webidl(dictionary)] struct Empty;` — deriving the dictionary converter on a fieldless unit struct.

Common situations: Placeholder/marker types accidentally getting the derive; a struct whose fields were all removed during refactoring.

Related errors


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