{"record":{"id":"ae021266ae9a8213","repo":"pydantic/monty","slug":"varargs-fields-must-be-vec-value-coerce-elements-in-the","errorCode":null,"errorMessage":"`varargs` fields must be `Vec<Value>` — coerce elements in the function body","messagePattern":"`varargs` fields must be `Vec<Value>` — coerce elements in the function body","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/monty-macros/src/from_args.rs","lineNumber":307,"sourceCode":"            if field.default.is_some() {\n                seen_positional_default = true;\n            } else if seen_positional_default {\n                return Err(syn::Error::new(\n                    field.ident.span(),\n                    \"required positional fields must come before positional fields with \\\n                     defaults — matching Python signatures, and relied on by the runtime \\\n                     binder's fast path\",\n                ));\n            }\n        }\n\n        // Raw binding is deliberately separate from conversion (that split is\n        // what reproduces CPython's error orderings), so `*args` elements are\n        // handed over unconverted.\n        if let Some(idx) = self.varargs_idx\n            && !is_vec_of_value(&self.fields[idx].ty)\n        {\n            return Err(syn::Error::new(\n                self.fields[idx].ident.span(),\n                \"`varargs` fields must be `Vec<Value>` — coerce elements in the function body\",\n            ));\n        }\n\n        // The runtime binder's fast paths return before the aggregated\n        // missing-keyword check runs, so a required kw_only slot could slip\n        // through binding unfilled and later surface `Bound::require`'s\n        // positional wording. No current signature needs one; reject until\n        // the fast paths learn to check for them.\n        if let Some(field) = self\n            .fields\n            .iter()\n            .find(|f| matches!(f.kind, FieldKind::KwOnly) && f.default.is_none())\n        {\n            return Err(syn::Error::new(\n                field.ident.span(),\n                \"keyword-only fields must have a `default` — the runtime binder's fast \\","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-macros/src/from_args.rs#L289-L325","documentation":"A compile-time validation error from the `FromArgs` derive: a `#[from_args(varargs)]` field (Python's `*args`) must have type `Vec<Value>`. Elements are bound raw, without conversion, so that CPython's error ordering can be reproduced by coercing in the function body.","triggerScenarios":"Declaring a field annotated `#[from_args(varargs)]` with any type other than `Vec<Value>`, e.g. `Vec<String>` or `Vec<u64>`.","commonSituations":"Trying to make the macro do per-element type conversion for `*args`; copying a `Vec<T>` pattern from a non-varargs field; porting a Rust function signature directly into the args struct.","solutions":["Change the field type to `Vec<Value>`","Coerce each element in the function body after `from_args` (e.g. with `value_to_u64`), raising the appropriate error in CPython's order","Use fixed named fields with `FromValue` types if element conversion should be automatic"],"exampleFix":"// before\n#[derive(FromArgs)]\nstruct Args {\n    #[from_args(varargs)]\n    nums: Vec<u64>,\n}\n// after\n#[derive(FromArgs)]\nstruct Args {\n    #[from_args(varargs)]\n    nums: Vec<Value>,\n}\n// then in body: nums.into_iter().map(|v| value_to_u64(v)).collect::<Result<Vec<_>,_>>()","handlingStrategy":"validation","validationCode":"#[derive(FromArgs)]\nstruct Args { #[from_args(varargs)] rest: Vec<Value> } // only legal varargs type","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always type varargs fields as Vec<Value>","Do element coercion in the function body to preserve CPython error ordering","Treat raw binding as intentional: conversion is a body-level concern"],"tags":["rust","proc-macro","compile-time","varargs"],"backgroundTag":"type-mismatch","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}