{"record":{"id":"4a83e0c42bc8ff07","repo":"pydantic/monty","slug":"default-and-static-string-cannot-be-applied-to-varargs","errorCode":null,"errorMessage":"`default` and `static_string` cannot be applied to `varargs` / `varkwargs` fields — they configure a named parameter slot, which collector fields don't own","messagePattern":"`default` and `static_string` cannot be applied to `varargs` / `varkwargs` fields — they configure a named parameter slot, which collector fields don't own","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/monty-macros/src/from_args.rs","lineNumber":337,"sourceCode":"            .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 \\\n                 paths skip the aggregated missing-keyword check, so a required \\\n                 keyword-only parameter would report the wrong error; extend the binder \\\n                 before allowing this\",\n            ));\n        }\n\n        // `default` / `static_string` describe a named parameter slot; on the\n        // collector fields they would be silently dead configuration.\n        for idx in [self.varargs_idx, self.varkwargs_idx].into_iter().flatten() {\n            let field = &self.fields[idx];\n            if field.default.is_some() || field.static_string.is_some() {\n                return Err(syn::Error::new(\n                    field.ident.span(),\n                    \"`default` and `static_string` cannot be applied to `varargs` / \\\n                     `varkwargs` fields — they configure a named parameter slot, which \\\n                     collector fields don't own\",\n                ));\n            }\n        }\n\n        Ok(())\n    }\n\n    fn render(&self) -> TokenStream {\n        let struct_ident = &self.struct_ident;\n        // Dedicated owning-slots struct: holds the raw `Bound` returned by the\n        // runtime binder plus one typed `Option` per named field. A `DropGuard`\n        // around it centralises error-path cleanup in one `DropWithContext` impl,\n        // so every conversion site is a plain `?`.\n        let slots_struct_ident = format_ident!(\"__{}Slots\", struct_ident);","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-macros/src/from_args.rs#L319-L355","documentation":"A compile-time validation error from the `FromArgs` derive: `#[from_args(default)]` and `#[from_args(static_string)]` configure a single named parameter slot, so they are rejected on `varargs`/`varkwargs` collector fields, where they would be silently ignored.","triggerScenarios":"Annotating a `#[from_args(varargs)]` or `#[from_args(varkwargs)]` field with `default` or `static_string`, e.g. `#[from_args(varkwargs, default)] options: ...`.","commonSituations":"Copy-pasting attribute lists from a normal field onto a collector field; trying to express 'default to empty collection' without realizing collectors already start empty.","solutions":["Remove the `default`/`static_string` attribute from the collector field — it is always initialized empty","Apply `default`/`static_string` only to named (positional or kw-only) fields","Handle any 'missing' fallback in the function body instead"],"exampleFix":"// before\n#[derive(FromArgs)]\nstruct Args {\n    #[from_args(varargs, default)]\n    extra: Vec<Value>,\n}\n// after\n#[derive(FromArgs)]\nstruct Args {\n    #[from_args(varargs)]\n    extra: Vec<Value>, // always present, empty when no args\n}","handlingStrategy":"validation","validationCode":"// collectors (varargs/varkwargs) accept no default/static_string attributes\n#[from_args(varargs)] extra: Vec<Value>,","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep collector fields bare — they always initialize empty","Apply default/static_string only to named parameter fields","Do fallback logic in the function body, not via attributes"],"tags":["rust","proc-macro","compile-time","attributes"],"backgroundTag":"conflicting-config-options","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"}