{"record":{"id":"7dd55acd853cbfc1","repo":"denoland/deno","slug":"structs-do-not-support-enum-converters","errorCode":null,"errorMessage":"Structs do not support enum converters","messagePattern":"Structs do not support enum converters","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/webidl/mod.rs","lineNumber":38,"sourceCode":"  let input = parse2::<DeriveInput>(item)?;\n  let span = input.span();\n  let ident = input.ident;\n  let ident_string = ident.to_string();\n  let converter = input\n    .attrs\n    .into_iter()\n    .find_map(|attr| ConverterType::from_attribute(attr).transpose())\n    .ok_or_else(|| {\n      Error::new(span, \"missing top-level #[webidl] attribute\")\n    })??;\n\n  let out = match input.data {\n    Data::Struct(data) => match converter {\n      ConverterType::Dictionary => {\n        create_impl(ident, dictionary::get_body(ident_string, span, data)?)\n      }\n      ConverterType::Enum => {\n        return Err(Error::new(span, \"Structs do not support enum converters\"));\n      }\n    },\n    Data::Enum(data) => match converter {\n      ConverterType::Dictionary => {\n        return Err(Error::new(\n          span,\n          \"Enums currently do not support dictionary converters\",\n        ));\n      }\n      ConverterType::Enum => {\n        let (body, as_str) = r#enum::get_body(ident_string, &ident, data)?;\n        let implementation = create_impl(ident, body);\n\n        quote! {\n          #implementation\n          #as_str\n        }\n      }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/webidl/mod.rs#L20-L56","documentation":"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.","triggerScenarios":"`#[webidl(enum)] struct Color { ... }` — annotating a struct with the enum converter.","commonSituations":"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.","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)]`."],"exampleFix":"// before\n#[derive(WebIDL)]\n#[webidl(enum)]\nstruct ColorMode { pub value: String }\n\n// after\n#[derive(WebIDL)]\n#[webidl(dictionary)]\nstruct ColorMode { pub value: String }","handlingStrategy":"validation","validationCode":"// Compile-time: `cargo check`. Pairing rule:\n//   struct  -> #[webidl(dictionary)]\n//   enum    -> #[webidl(enum)]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["webidl","proc-macro","derive-macro","converter-mismatch","compile-time"],"backgroundTag":"converter-type-mismatch","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"}