{"record":{"id":"73b0dcfae6a23a9c","repo":"actix/actix-web","slug":"multipartform-can-only-be-derived-for-a-struct-w","errorCode":null,"errorMessage":"`MultipartForm` can only be derived for a struct with named fields","messagePattern":"`MultipartForm` can only be derived for a struct with named fields","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"actix-multipart-derive/src/lib.rs","lineNumber":76,"sourceCode":"pub fn impl_multipart_form(input: proc_macro::TokenStream) -> proc_macro::TokenStream {\n    let input: syn::DeriveInput = parse_macro_input!(input);\n\n    let name = &input.ident;\n\n    let data_struct = match &input.data {\n        syn::Data::Struct(data_struct) => data_struct,\n        _ => {\n            return compile_err(syn::Error::new(\n                input.ident.span(),\n                \"`MultipartForm` can only be derived for structs\",\n            ))\n        }\n    };\n\n    let fields = match &data_struct.fields {\n        syn::Fields::Named(fields_named) => fields_named,\n        _ => {\n            return compile_err(syn::Error::new(\n                input.ident.span(),\n                \"`MultipartForm` can only be derived for a struct with named fields\",\n            ))\n        }\n    };\n\n    let attrs = match MultipartFormAttrs::from_derive_input(&input) {\n        Ok(attrs) => attrs,\n        Err(err) => return err.write_errors().into(),\n    };\n\n    // Parse the field attributes\n    let parsed = match fields\n        .named\n        .iter()\n        .map(|field| {\n            let rust_name = field.ident.as_ref().unwrap();\n            let attrs = FieldAttrs::from_field(field).map_err(|err| err.write_errors())?;","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/actix/actix-web/blob/4d435abc281842f3cbee165b6cde739e001d3a25/actix-multipart-derive/src/lib.rs#L58-L94","documentation":"This is a compile-time error from the `#[derive(MultipartForm)]` proc macro. The derive only accepts structs with named fields because it needs field identifiers to generate per-field handling code (limits, state extraction, etc.). Tuple structs (`struct Foo(String)`) and unit structs (`struct Foo;`) are rejected because the macro cannot map multipart field names to unnamed positions.","triggerScenarios":"Annotating a tuple struct (e.g., `#[derive(MultipartForm)] struct Upload(Bytes);`) or a unit struct (`struct Empty;`) with `#[derive(MultipartForm)]`. The macro matches `data_struct.fields` against `syn::Fields::Named` at line 73-81 and returns this error for `Unnamed` or `Unit`.","commonSituations":"Developers new to actix-multipart who try to derive on a tuple struct, or who copy a serde pattern using unnamed fields. Refactoring a named-field struct into a tuple struct without removing the derive.","solutions":["Change the struct to use named fields: `struct Upload { file: Bytes }` instead of `struct Upload(Bytes);`","If you need a single-field wrapper, still give it a name: `struct Upload { data: Bytes }`","Remove `#[derive(MultipartForm)]` if the type is not actually used as a multipart form extractor"],"exampleFix":"// before\n#[derive(MultipartForm)]\nstruct Upload(Bytes);\n\n// after\n#[derive(MultipartForm)]\nstruct Upload {\n    data: Bytes,\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// No runtime guard needed; this is a compile-time error.\n// Ensure the struct uses named fields:\n// pub struct MyForm {\n//     field1: Bytes,\n//     field2: String,\n// }\n// Verify with: cargo check","tryCatchPattern":null,"preventionTips":["Always use named fields on structs annotated with #[derive(MultipartForm)]","Run cargo check early after adding the derive to catch structural mismatches","Review the actix-multipart form documentation for the expected struct shape"],"tags":["rust","actix-web","multipart","derive-macro","compile-time"],"backgroundTag":null,"analyzedSha":"4d435abc281842f3cbee165b6cde739e001d3a25","analyzedAt":"2026-08-09T01:01:40.926Z","contentChangedAt":"2026-08-09T01:01:40.926Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}