Skip to content

Commit 22f853c

Browse files
committed
Avoid looping past bounds of args
There might be more type params than args to a method call, which leads to an index out of bounds panic.
1 parent a3c9eed commit 22f853c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
323323
let mut param_found = FxHashMap::default();
324324
if self.can_eq(self.param_env, ty, found).is_ok() {
325325
// We only point at the first place where the found type was inferred.
326-
for (i, param_ty) in sig.inputs().skip_binder().iter().skip(1).enumerate() {
326+
for (param_ty, arg) in sig.inputs().skip_binder().iter().skip(1).zip(args) {
327327
if def_self_ty.contains(*param_ty) && let ty::Param(_) = param_ty.kind() {
328328
// We found an argument that references a type parameter in `Self`,
329329
// so we assume that this is the argument that caused the found
330330
// type, which we know already because of `can_eq` above was first
331331
// inferred in this method call.
332-
let arg = &args[i];
333332
let arg_ty = self.node_ty(arg.hir_id);
334333
if !arg.span.overlaps(mismatch_span) {
335334
err.span_label(

0 commit comments

Comments
 (0)