rust-lang/rust · error
arg must exist for infer
Error message
arg must exist for infer
What it means
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.
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.
Defensive patterns
Strategy: validation
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Unstable delegation with partially-inferred generic args; a mismatch in the delegation generics-resolution accounting.
Related errors
- must be at least one segment
- must contain self type as `SelfTy` propagation kind is…
- `Self` generic param is not found while expected
- alt layout should always work
- alt layout should have a niche like the regular one
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/0323c5fe8d6f084f.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/rustc_ast_lowering/src/delegation/mod.rs:500
fn process_segment(
&mut self,
span: Span,
segment: &hir::PathSegment<'hir>,
result: &mut GenericsGenerationResult<'hir>,
) -> hir::PathSegment<'hir> {
let infer_indices = result.generics.infer_indices();
result.generics.into_hir_generics(self, span);
let mut segment = segment.clone();
let mut args_iter = result.generics.create_args_iterator();
let new_args = segment
.args
.filter(|args| !args.is_empty())
.map(|args| {
self.arena.alloc_from_iter(args.args.iter().enumerate().map(|(idx, arg)| {
if infer_indices.contains(&idx) {
args_iter.next(self, |_| arg.hir_id()).expect("arg must exist for infer")
} else {
*arg
}
}))
})
.unwrap_or_else(|| self.arena.alloc_from_iter(args_iter.consume_all(self)));
// Do not omit constraints as there might be some and they must be present in HIR (#158812).
let has_constraints = segment.args.is_some_and(|a| !a.constraints.is_empty());
// Needed for better error messages (`trait-impl-wrong-args-count.rs` test).
segment.args = (has_constraints || !new_args.is_empty()).then(|| {
&*self.arena.alloc(hir::GenericArgs {
args: new_args,
constraints: segment.args.map(|a| a.constraints).unwrap_or(&[]),
parenthesized: hir::GenericArgsParentheses::No,
span_ext: segment.args.map_or(span, |args| args.span_ext),
})View on GitHub (pinned to 7088e4b63a)