{"record":{"id":"eda5ce4c33323468","repo":"denoland/deno","slug":"unit-fields-are-currently-not-supported-eda5ce","errorCode":null,"errorMessage":"Unit fields are currently not supported","messagePattern":"Unit fields are currently not supported","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/webidl/dictionary.rs","lineNumber":39,"sourceCode":"use syn::spanned::Spanned;\n\nuse super::kw;\n\npub fn get_body(\n  ident_string: String,\n  span: Span,\n  data: DataStruct,\n) -> Result<TokenStream, Error> {\n  let fields = match data.fields {\n    Fields::Named(fields) => fields,\n    Fields::Unnamed(_) => {\n      return Err(Error::new(\n        span,\n        \"Unnamed fields are currently not supported\",\n      ));\n    }\n    Fields::Unit => {\n      return Err(Error::new(span, \"Unit fields are currently not supported\"));\n    }\n  };\n\n  let mut fields = fields\n    .named\n    .into_iter()\n    .map(TryInto::try_into)\n    .collect::<Result<Vec<DictionaryField>, Error>>()?;\n  fields.sort_by(|a, b| a.name.cmp(&b.name));\n\n  let names = fields\n    .iter()\n    .map(|field| field.name.clone())\n    .collect::<Vec<_>>();\n\n  let fields = fields.into_iter().map(|field| {\n    let field_name = field.name;\n    let js_name = field.js_name.to_string();","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/webidl/dictionary.rs#L21-L57","documentation":"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.","triggerScenarios":"`#[derive(WebIDL)] #[webidl(dictionary)] struct Empty;` — deriving the dictionary converter on a fieldless unit struct.","commonSituations":"Placeholder/marker types accidentally getting the derive; a struct whose fields were all removed during refactoring.","solutions":["Give the struct named members, or if it is intentionally empty, drop the `#[derive(WebIDL)]` / `#[webidl(dictionary)]` attributes entirely.","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."],"exampleFix":"// before\n#[derive(WebIDL)]\n#[webidl(dictionary)]\nstruct EmptyFlags;\n\n// after\n#[derive(WebIDL)]\n#[webidl(dictionary)]\nstruct EmptyFlags { pub verbose: bool }","handlingStrategy":"validation","validationCode":"// Compile-time: `cargo check`. Unit structs cannot be dictionaries;\n// give the struct at least one named field or drop the derive.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't attach `#[derive(WebIDL)]` to marker/placeholder types.","After removing all fields during refactoring, also remove the webidl attributes."],"tags":["webidl","proc-macro","derive-macro","unit-struct","compile-time"],"backgroundTag":"unsupported-struct-shape","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}