diff options
| author | Martin Gammelsæter <martin@mg.am> | 2023-02-14 16:11:15 +0100 |
|---|---|---|
| committer | Martin Gammelsæter <martin@mg.am> | 2023-02-14 16:11:15 +0100 |
| commit | 22f853c620d970c6f80c8c206614a3bf766d028f (patch) | |
| tree | 157f32fb1d66addbc1d0be50c269876dacb19f0e | |
| parent | a3c9eede5d50be0231f229bf28a271cd509861a3 (diff) | |
| download | rust-22f853c620d970c6f80c8c206614a3bf766d028f.tar.gz rust-22f853c620d970c6f80c8c206614a3bf766d028f.zip | |
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.
| -rw-r--r-- | compiler/rustc_hir_typeck/src/demand.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index ae00042eae7..16d3115c233 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -323,13 +323,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut param_found = FxHashMap::default(); if self.can_eq(self.param_env, ty, found).is_ok() { // We only point at the first place where the found type was inferred. - for (i, param_ty) in sig.inputs().skip_binder().iter().skip(1).enumerate() { + for (param_ty, arg) in sig.inputs().skip_binder().iter().skip(1).zip(args) { if def_self_ty.contains(*param_ty) && let ty::Param(_) = param_ty.kind() { // We found an argument that references a type parameter in `Self`, // so we assume that this is the argument that caused the found // type, which we know already because of `can_eq` above was first // inferred in this method call. - let arg = &args[i]; let arg_ty = self.node_ty(arg.hir_id); if !arg.span.overlaps(mismatch_span) { err.span_label( |
