{"record":{"id":"e8054b74d32b4291","repo":"diesel-rs/diesel","slug":"auto-type-unexpected-double-type-ascription","errorCode":null,"errorMessage":"auto_type: unexpected double type ascription","messagePattern":"auto_type: unexpected double type ascription","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"dsl_auto_type/src/auto_type/local_variables_map.rs","lineNumber":48,"sourceCode":"}\n\nimpl<'a> LocalVariablesMap<'a, '_> {\n    pub(crate) fn process_pat(\n        &mut self,\n        pat: &'a syn::Pat,\n        type_ascription: Option<&'a Type>,\n        local_init_expression: Option<&'a syn::Expr>,\n    ) -> Result<(), syn::Error> {\n        // Either the let statement hints the type or we have to infer it\n        // Either the let statement is a simple assignment or a destructuring assignment\n        match pat {\n            syn::Pat::Type(pat_type) => {\n                self.process_pat(\n                    &pat_type.pat,\n                    Some(match type_ascription {\n                        None => &pat_type.ty,\n                        Some(type_ascription) => {\n                            return Err(syn::Error::new(\n                                type_ascription.span(),\n                                \"auto_type: unexpected double type ascription\",\n                            ));\n                        }\n                    }),\n                    local_init_expression,\n                )?;\n            }\n            syn::Pat::Ident(pat_ident) => {\n                self.inner.map.insert(\n                    &pat_ident.ident,\n                    match (type_ascription, local_init_expression) {\n                        (opt_type_ascription, Some(expr)) => {\n                            let inferrer = self.inferrer();\n                            LetStatementInferredType {\n                                type_: inferrer.infer_expression_type(expr, opt_type_ascription),\n                                errors: inferrer.into_errors(),\n                            }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/dsl_auto_type/src/auto_type/local_variables_map.rs#L30-L66","documentation":"dsl_auto_type walks each let-pattern to collect variable/type mappings. A pattern like `let x: T: U` (or a type-ascribed pattern that itself contains another type-ascribed subpattern) yields two type ascriptions for the same binding; since the macro can only pick one, it fails compilation with this error.","triggerScenarios":"Writing a let statement whose pattern applies type ascription twice, e.g. `let (a: i32): (i32,) = ...` or nested `x: T` patterns under an already-ascribed tuple pattern while processing `Pat::Type` recursively with an existing ascription.","commonSituations":"Rare hand-written double annotations, often from mechanically editing `let x: T = ...` into a tuple pattern or from macros generating nested ascribed patterns; also from refactoring tuple destructuring where the outer tuple and inner element are both annotated.","solutions":["Remove the redundant inner type ascription, keeping only one per binding.","Keep only the outer tuple-level ascription: `let (a, b): (i32, String) = ...;` instead of annotating elements again.","If this comes from a generated macro, fix the generator to emit a single ascription at one level."],"exampleFix":"// before\nlet (a: i32): (i32,) = (1,);\n// after\nlet (a,): (i32,) = (1,);","handlingStrategy":"validation","validationCode":"// Ensure each binding has at most one type ascription level:\n// pattern_writes_type(pat) == false || outer_ascription.is_none()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never nest `pat: Type` inside an already-ascribed pattern.","Put ascriptions at the tuple level, not per element, when destructuring."],"tags":["rust","proc-macro","patterns","compile-time"],"backgroundTag":"invalid-argument-format","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}