mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-19 19:17:31 +00:00
Do not repeat idx
This commit is contained in:
parent
0f6312f643
commit
bbfbecd59f
@ -1156,14 +1156,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// ```
|
// ```
|
||||||
// which includes the replacement of the first two `()` for the correct type, and the
|
// which includes the replacement of the first two `()` for the correct type, and the
|
||||||
// removal of the last `()`.
|
// removal of the last `()`.
|
||||||
let mut prev = -1;
|
let mut idx = -1;
|
||||||
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() {
|
for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() {
|
||||||
// We want to point not at the *current* argument expression index, but rather at the
|
// We want to point not at the *current* argument expression index, but rather at the
|
||||||
// index position where it *should have been*, which is *after* the previous one.
|
// index position where it *should have been*, which is *after* the previous one.
|
||||||
if let Some(provided_idx) = provided_idx {
|
idx = match provided_idx {
|
||||||
prev = provided_idx.index() as i64;
|
Some(provided_idx) => provided_idx.index() as i64 + 1,
|
||||||
}
|
None => idx + 1,
|
||||||
let idx = ProvidedIdx::from_usize((prev + 1) as usize);
|
};
|
||||||
|
let idx = ProvidedIdx::from_usize(idx as usize);
|
||||||
if let None = provided_idx
|
if let None = provided_idx
|
||||||
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
|
&& let Some((_, arg_span)) = provided_arg_tys.get(idx)
|
||||||
{
|
{
|
||||||
|
9
tests/ui/argument-suggestions/109831.rs
Normal file
9
tests/ui/argument-suggestions/109831.rs
Normal file
@ -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
tests/ui/argument-suggestions/109831.stderr
Normal file
51
tests/ui/argument-suggestions/109831.stderr
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
error[E0412]: cannot find type `C` in this scope
|
||||||
|
--> $DIR/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/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/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/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`.
|
Loading…
Reference in New Issue
Block a user