Skip to content

Commit b80ee39

Browse files
committed
Auto merge of rust-lang#109850 - MU001999:master, r=estebank
Emits non-overlapping suggestions for arguments with wrong types Fixes rust-lang#109831
2 parents 5ca6e98 + 80e4285 commit b80ee39

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1191,11 +1191,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11911191
// index position where it *should have been*, which is *after* the previous one.
11921192
if let Some(provided_idx) = provided_idx {
11931193
prev = provided_idx.index() as i64;
1194+
continue;
11941195
}
11951196
let idx = ProvidedIdx::from_usize((prev + 1) as usize);
1196-
if let None = provided_idx
1197-
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
1198-
{
1197+
if let Some((_, arg_span)) = provided_arg_tys.get(idx) {
1198+
prev += 1;
11991199
// There is a type that was *not* found anywhere, so it isn't a move, but a
12001200
// replacement and we look at what type it should have been. This will allow us
12011201
// To suggest a multipart suggestion when encountering `foo(1, "")` where the def
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/issue-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/issue-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/issue-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/issue-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)