Skip to content

Commit 80e4285

Browse files
committed
Make each idx is used once
1 parent bbfbecd commit 80e4285

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1156,18 +1156,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11561156
// ```
11571157
// which includes the replacement of the first two `()` for the correct type, and the
11581158
// removal of the last `()`.
1159-
let mut idx = -1;
1159+
let mut prev = -1;
11601160
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() {
11611161
// We want to point not at the *current* argument expression index, but rather at the
11621162
// index position where it *should have been*, which is *after* the previous one.
1163-
idx = match provided_idx {
1164-
Some(provided_idx) => provided_idx.index() as i64 + 1,
1165-
None => idx + 1,
1166-
};
1167-
let idx = ProvidedIdx::from_usize(idx as usize);
1168-
if let None = provided_idx
1169-
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
1170-
{
1163+
if let Some(provided_idx) = provided_idx {
1164+
prev = provided_idx.index() as i64;
1165+
continue;
1166+
}
1167+
let idx = ProvidedIdx::from_usize((prev + 1) as usize);
1168+
if let Some((_, arg_span)) = provided_arg_tys.get(idx) {
1169+
prev += 1;
11711170
// There is a type that was *not* found anywhere, so it isn't a move, but a
11721171
// replacement and we look at what type it should have been. This will allow us
11731172
// To suggest a multipart suggestion when encountering `foo(1, "")` where the def

tests/ui/argument-suggestions/109831.stderr renamed to tests/ui/argument-suggestions/issue-109831.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `C` in this scope
2-
--> $DIR/109831.rs:4:24
2+
--> $DIR/issue-109831.rs:4:24
33
|
44
LL | struct A;
55
| --------- similarly named struct `A` defined here
@@ -17,7 +17,7 @@ LL | fn f<C>(b1: B, b2: B, a2: C) {}
1717
| +++
1818

1919
error[E0425]: cannot find value `C` in this scope
20-
--> $DIR/109831.rs:7:16
20+
--> $DIR/issue-109831.rs:7:16
2121
|
2222
LL | struct A;
2323
| --------- similarly named unit struct `A` defined here
@@ -26,7 +26,7 @@ LL | f(A, A, B, C);
2626
| ^ help: a unit struct with a similar name exists: `A`
2727

2828
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
29-
--> $DIR/109831.rs:7:5
29+
--> $DIR/issue-109831.rs:7:5
3030
|
3131
LL | f(A, A, B, C);
3232
| ^ - - - unexpected argument
@@ -35,7 +35,7 @@ LL | f(A, A, B, C);
3535
| expected `B`, found `A`
3636
|
3737
note: function defined here
38-
--> $DIR/109831.rs:4:4
38+
--> $DIR/issue-109831.rs:4:4
3939
|
4040
LL | fn f(b1: B, b2: B, a2: C) {}
4141
| ^ ----- ----- -----

0 commit comments

Comments
 (0)