{"record":{"id":"0323c5fe8d6f084f","repo":"rust-lang/rust","slug":"arg-must-exist-for-infer","errorCode":null,"errorMessage":"arg must exist for infer","messagePattern":"arg must exist for infer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_ast_lowering/src/delegation/mod.rs","lineNumber":500,"sourceCode":"    fn process_segment(\n        &mut self,\n        span: Span,\n        segment: &hir::PathSegment<'hir>,\n        result: &mut GenericsGenerationResult<'hir>,\n    ) -> hir::PathSegment<'hir> {\n        let infer_indices = result.generics.infer_indices();\n        result.generics.into_hir_generics(self, span);\n\n        let mut segment = segment.clone();\n        let mut args_iter = result.generics.create_args_iterator();\n\n        let new_args = segment\n            .args\n            .filter(|args| !args.is_empty())\n            .map(|args| {\n                self.arena.alloc_from_iter(args.args.iter().enumerate().map(|(idx, arg)| {\n                    if infer_indices.contains(&idx) {\n                        args_iter.next(self, |_| arg.hir_id()).expect(\"arg must exist for infer\")\n                    } else {\n                        *arg\n                    }\n                }))\n            })\n            .unwrap_or_else(|| self.arena.alloc_from_iter(args_iter.consume_all(self)));\n\n        // Do not omit constraints as there might be some and they must be present in HIR (#158812).\n        let has_constraints = segment.args.is_some_and(|a| !a.constraints.is_empty());\n\n        // Needed for better error messages (`trait-impl-wrong-args-count.rs` test).\n        segment.args = (has_constraints || !new_args.is_empty()).then(|| {\n            &*self.arena.alloc(hir::GenericArgs {\n                args: new_args,\n                constraints: segment.args.map(|a| a.constraints).unwrap_or(&[]),\n                parenthesized: hir::GenericArgsParentheses::No,\n                span_ext: segment.args.map_or(span, |args| args.span_ext),\n            })","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_ast_lowering/src/delegation/mod.rs#L482-L518","documentation":"delegation/mod.rs:500: while rewriting generic args, for each index contained in result.generics.infer_indices(), the code pulls the next synthesized arg from args_iter via .next(...).expect(\"arg must exist for infer\"). The invariant: the number of infer indices never exceeds the number of args the iterator can produce.","triggerScenarios":"Delegation generic resolution computes infer_indices whose count is greater than the args the create_args_iterator yields, e.g. a mismatch between inferred arg slots and available generic parameters.","commonSituations":"Unstable delegation with partially-inferred generic args; a mismatch in the delegation generics-resolution accounting.","solutions":["File a rustc ICE with the minimized delegation generic-args repro.","Provide explicit generic args on the delegation path so fewer slots are inferred.","Remove angle-bracketed args / constraints on the delegation to reduce resolution complexity.","Bisect with cargo bisect-rustc across nightlies."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide explicit generic args on delegation paths to reduce inferred-arg slots.","Avoid mixing angle-bracketed constraints with delegation generics.","File a rustc ICE with the minimized delegation generic-args repro.","Bisect with cargo bisect-rustc and pin to a known-good nightly."],"tags":["rust","delegation","generics","ice"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}