{"record":{"id":"a622febd5218b7e5","repo":"FuelLabs/fuels-rs","slug":"must-have-exactly-one-element","errorCode":null,"errorMessage":"must have exactly one element","messagePattern":"must have exactly one element","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/fuels-macros/src/parse_utils.rs","lineNumber":163,"sourceCode":"        Ok(Members {\n            members,\n            fuels_core_path,\n        })\n    }\n\n    pub(crate) fn from_enum(data: DataEnum, fuels_core_path: TokenStream) -> syn::Result<Self> {\n        let members = data\n            .variants\n            .into_iter()\n            .map(|variant: Variant| {\n                let name = variant.ident;\n                if has_ignore_attr(&variant.attrs) {\n                    Ok(Member::Ignored { name })\n                } else {\n                    let ty = match variant.fields {\n                        Fields::Unnamed(fields_unnamed) => {\n                            if fields_unnamed.unnamed.len() != 1 {\n                                return Err(Error::new(\n                                    fields_unnamed.paren_token.span.join(),\n                                    \"must have exactly one element\",\n                                ));\n                            }\n                            fields_unnamed.unnamed.into_iter().next()\n                        }\n                        Fields::Unit => None,\n                        Fields::Named(named_fields) => {\n                            return Err(Error::new_spanned(\n                                named_fields,\n                                \"struct-like enum variants are not supported\",\n                            ));\n                        }\n                    }\n                    .map(|field| field.ty.into_token_stream())\n                    .unwrap_or_else(|| quote! {()});\n                    Ok(Member::Normal { name, ty })\n                }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/FuelLabs/fuels-rs/blob/d9a250a51818dda64bfeb5ef7cc19cf27bdcd623/packages/fuels-macros/src/parse_utils.rs#L145-L181","documentation":"Compile-time error from the fuels macros crate: when deriving Fuel-typed ABI encoding for an enum, a variant with unnamed (tuple) fields must carry exactly one field. The derive walks each variant and treats a single unnamed field as the variant's payload type; anything else (0 fields is fine as Unit, but 2+ unnamed fields, or the error span on the parens) is rejected with this message.","triggerScenarios":"Applying #[derive(FuelTypes)]/the fuels type-generation derive (directly or via the macro pipeline in packages/fuels-macros) to an enum with a variant like TooMany(u64, bool) or NoFields() — i.e. Fields::Unnamed whose unnamed.len() != 1. Named-field variants fail separately ('struct-like enum variants are not supported'); unit variants are allowed.","commonSituations":"Porting a Rust enum with multi-field tuple variants to a Fuel contract type; modeling sum types the way serde/serde_json allow and expecting the same flexibility; adding a second field for metadata (e.g. MyVariant(Data, PhantomData)).","solutions":["Reduce each tuple variant to exactly one field, wrapping extras in a struct: TooMany(Pair) where struct Pair { a: u64, b: bool } and derive on the struct too.","If the extra field is a marker (PhantomData), move it into a wrapper struct instead of the variant.","Alternatively switch the variant to unit-only and pass data through a separate type.","Check for an #[ignore] attribute if the variant is intentionally not part of the ABI (has_ignore_attr skips it)."],"exampleFix":"// before\n#[derive(FuelTypes)]\nenum Status {\n    Failed(String, u64),\n}\n// after\n#[derive(FuelTypes)]\nstruct Failure {\n    msg: String,\n    code: u64,\n}\n#[derive(FuelTypes)]\nenum Status {\n    Failed(Failure),\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":"// compile-time 'guard': keep tuple variants single-field by construction\ntrait FuelAbiEnumShape {\n    const OK: bool;\n}\n// convention: any enum used in ABI types has variants of form V(T) or V; reject V(T, U) in review\nfn _assert_single_payload<T, U>() where U: FuelAbiEnumShape {}","tryCatchPattern":null,"preventionTips":["Model multi-field payloads as a struct and derive the Fuel types on the struct too.","Run cargo check on the crate as soon as the derive is added — this error is compile-time.","Check for an #[ignore] attribute if the variant must stay in the enum but out of the ABI."],"tags":["rust","macro","compile-time","enum","fuels-macros"],"backgroundTag":null,"analyzedSha":"d9a250a51818dda64bfeb5ef7cc19cf27bdcd623","analyzedAt":"2026-08-16T09:49:30.618Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}