Skip to content

Commit bbfbecd

Browse files
committed
Do not repeat idx
1 parent 0f6312f commit bbfbecd

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1156,14 +1156,15 @@ 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 prev = -1;
1159+
let mut idx = -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-
if let Some(provided_idx) = provided_idx {
1164-
prev = provided_idx.index() as i64;
1165-
}
1166-
let idx = ProvidedIdx::from_usize((prev + 1) as usize);
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);
11671168
if let None = provided_idx
11681169
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
11691170
{
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct A;
2+
struct B;
3+
4+
fn f(b1: B, b2: B, a2: C) {} //~ ERROR E0412
5+
6+
fn main() {
7+
f(A, A, B, C); //~ ERROR E0425
8+
//~^ ERROR E0061
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error[E0412]: cannot find type `C` in this scope
2+
--> $DIR/109831.rs:4:24
3+
|
4+
LL | struct A;
5+
| --------- similarly named struct `A` defined here
6+
...
7+
LL | fn f(b1: B, b2: B, a2: C) {}
8+
| ^
9+
|
10+
help: a struct with a similar name exists
11+
|
12+
LL | fn f(b1: B, b2: B, a2: A) {}
13+
| ~
14+
help: you might be missing a type parameter
15+
|
16+
LL | fn f<C>(b1: B, b2: B, a2: C) {}
17+
| +++
18+
19+
error[E0425]: cannot find value `C` in this scope
20+
--> $DIR/109831.rs:7:16
21+
|
22+
LL | struct A;
23+
| --------- similarly named unit struct `A` defined here
24+
...
25+
LL | f(A, A, B, C);
26+
| ^ help: a unit struct with a similar name exists: `A`
27+
28+
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
29+
--> $DIR/109831.rs:7:5
30+
|
31+
LL | f(A, A, B, C);
32+
| ^ - - - unexpected argument
33+
| | |
34+
| | expected `B`, found `A`
35+
| expected `B`, found `A`
36+
|
37+
note: function defined here
38+
--> $DIR/109831.rs:4:4
39+
|
40+
LL | fn f(b1: B, b2: B, a2: C) {}
41+
| ^ ----- ----- -----
42+
help: remove the extra argument
43+
|
44+
LL - f(A, A, B, C);
45+
LL + f(/* B */, /* B */, B);
46+
|
47+
48+
error: aborting due to 3 previous errors
49+
50+
Some errors have detailed explanations: E0061, E0412, E0425.
51+
For more information about an error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)