Skip to content

Emits non-overlapping suggestions for arguments with wrong types #109850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// index position where it *should have been*, which is *after* the previous one.
if let Some(provided_idx) = provided_idx {
prev = provided_idx.index() as i64;
continue;
}
let idx = ProvidedIdx::from_usize((prev + 1) as usize);
if let None = provided_idx
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
{
if let Some((_, arg_span)) = provided_arg_tys.get(idx) {
prev += 1;
// There is a type that was *not* found anywhere, so it isn't a move, but a
// replacement and we look at what type it should have been. This will allow us
// To suggest a multipart suggestion when encountering `foo(1, "")` where the def
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/argument-suggestions/issue-109831.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct A;
struct B;

fn f(b1: B, b2: B, a2: C) {} //~ ERROR E0412

fn main() {
f(A, A, B, C); //~ ERROR E0425
//~^ ERROR E0061
}
51 changes: 51 additions & 0 deletions tests/ui/argument-suggestions/issue-109831.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error[E0412]: cannot find type `C` in this scope
--> $DIR/issue-109831.rs:4:24
|
LL | struct A;
| --------- similarly named struct `A` defined here
...
LL | fn f(b1: B, b2: B, a2: C) {}
| ^
|
help: a struct with a similar name exists
|
LL | fn f(b1: B, b2: B, a2: A) {}
| ~
help: you might be missing a type parameter
|
LL | fn f<C>(b1: B, b2: B, a2: C) {}
| +++

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

error[E0061]: this function takes 3 arguments but 4 arguments were supplied
--> $DIR/issue-109831.rs:7:5
|
LL | f(A, A, B, C);
| ^ - - - unexpected argument
| | |
| | expected `B`, found `A`
| expected `B`, found `A`
|
note: function defined here
--> $DIR/issue-109831.rs:4:4
|
LL | fn f(b1: B, b2: B, a2: C) {}
| ^ ----- ----- -----
help: remove the extra argument
|
LL - f(A, A, B, C);
LL + f(/* B */, /* B */, B);
|

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0061, E0412, E0425.
For more information about an error, try `rustc --explain E0061`.