Skip to content
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

Use ordinal number in argument error #125042

Merged
merged 1 commit into from
Jul 18, 2024
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
19 changes: 17 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
"".to_string()
};
labels.push((provided_span, format!("unexpected argument{provided_ty_name}")));
let idx = if provided_arg_tys.len() == 1 {
"".to_string()
} else {
format!(" #{}", arg_idx.as_usize() + 1)
};
labels.push((
provided_span,
format!("unexpected argument{idx}{provided_ty_name}"),
));
let mut span = provided_span;
if span.can_be_used_for_suggestions()
&& error_span.can_be_used_for_suggestions()
Expand Down Expand Up @@ -1175,7 +1183,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
"".to_string()
};
labels.push((span, format!("an argument{rendered} is missing")));
labels.push((
span,
format!(
"argument #{}{rendered} is missing",
expected_idx.as_usize() + 1
),
));

suggestion_text = match suggestion_text {
SuggestionText::None => SuggestionText::Provide(false),
SuggestionText::Provide(_) => SuggestionText::Provide(true),
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/argument-suggestions/basic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied
--> $DIR/basic.rs:22:5
|
LL | missing();
| ^^^^^^^-- an argument of type `u32` is missing
| ^^^^^^^-- argument #1 of type `u32` is missing
|
note: function defined here
--> $DIR/basic.rs:15:4
Expand Down Expand Up @@ -86,7 +86,7 @@ error[E0057]: this function takes 1 argument but 0 arguments were supplied
--> $DIR/basic.rs:27:5
|
LL | closure();
| ^^^^^^^-- an argument is missing
| ^^^^^^^-- argument #1 is missing
|
note: closure defined here
--> $DIR/basic.rs:26:19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied
--> $DIR/display-is-suggestable.rs:6:5
|
LL | foo();
| ^^^-- an argument of type `&dyn std::fmt::Display + Send` is missing
| ^^^-- argument #1 of type `&dyn std::fmt::Display + Send` is missing
|
note: function defined here
--> $DIR/display-is-suggestable.rs:3:4
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/argument-suggestions/extern-fn-arg-names.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0061]: this function takes 2 arguments but 1 argument was supplied
--> $DIR/extern-fn-arg-names.rs:7:5
|
LL | dstfn(1);
| ^^^^^--- an argument is missing
| ^^^^^--- argument #2 is missing
|
note: function defined here
--> $DIR/extern-fn-arg-names.rs:2:8
Expand Down
56 changes: 28 additions & 28 deletions tests/ui/argument-suggestions/extra_arguments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:20:3
|
LL | empty(1, 1);
| ^^^^^ - - unexpected argument of type `{integer}`
| ^^^^^ - - unexpected argument #2 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #1 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:1:4
Expand All @@ -38,7 +38,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:22:3
|
LL | one_arg(1, 1);
| ^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -55,7 +55,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:23:3
|
LL | one_arg(1, "");
| ^^^^^^^ -- unexpected argument of type `&'static str`
| ^^^^^^^ -- unexpected argument #2 of type `&'static str`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -72,9 +72,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
--> $DIR/extra_arguments.rs:24:3
|
LL | one_arg(1, "", 1.0);
| ^^^^^^^ -- --- unexpected argument of type `{float}`
| ^^^^^^^ -- --- unexpected argument #3 of type `{float}`
| |
| unexpected argument of type `&'static str`
| unexpected argument #2 of type `&'static str`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -91,7 +91,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:26:3
|
LL | two_arg_same(1, 1, 1);
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^^^^^^ - unexpected argument #3 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:3:4
Expand All @@ -108,7 +108,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:27:3
|
LL | two_arg_same(1, 1, 1.0);
| ^^^^^^^^^^^^ --- unexpected argument of type `{float}`
| ^^^^^^^^^^^^ --- unexpected argument #3 of type `{float}`
|
note: function defined here
--> $DIR/extra_arguments.rs:3:4
Expand All @@ -125,7 +125,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:29:3
|
LL | two_arg_diff(1, 1, "");
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -142,7 +142,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:30:3
|
LL | two_arg_diff(1, "", "");
| ^^^^^^^^^^^^ -- unexpected argument of type `&'static str`
| ^^^^^^^^^^^^ -- unexpected argument #3 of type `&'static str`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -159,9 +159,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
--> $DIR/extra_arguments.rs:31:3
|
LL | two_arg_diff(1, 1, "", "");
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
| ^^^^^^^^^^^^ - -- unexpected argument #4 of type `&'static str`
| |
| unexpected argument of type `{integer}`
| unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -178,9 +178,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
--> $DIR/extra_arguments.rs:32:3
|
LL | two_arg_diff(1, "", 1, "");
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
| ^^^^^^^^^^^^ - -- unexpected argument #4 of type `&'static str`
| |
| unexpected argument of type `{integer}`
| unexpected argument #3 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -197,7 +197,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:35:3
|
LL | two_arg_same(1, 1, "");
| ^^^^^^^^^^^^ -- unexpected argument of type `&'static str`
| ^^^^^^^^^^^^ -- unexpected argument #3 of type `&'static str`
|
note: function defined here
--> $DIR/extra_arguments.rs:3:4
Expand All @@ -214,7 +214,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:36:3
|
LL | two_arg_diff(1, 1, "");
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -234,7 +234,7 @@ LL | two_arg_same(
| ^^^^^^^^^^^^
...
LL | ""
| -- unexpected argument of type `&'static str`
| -- unexpected argument #3 of type `&'static str`
|
note: function defined here
--> $DIR/extra_arguments.rs:3:4
Expand All @@ -255,7 +255,7 @@ LL | two_arg_diff(
| ^^^^^^^^^^^^
LL | 1,
LL | 1,
| - unexpected argument of type `{integer}`
| - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:4:4
Expand All @@ -271,12 +271,12 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:8:9
|
LL | empty($x, 1);
| ^^^^^ - unexpected argument of type `{integer}`
| ^^^^^ - unexpected argument #2 of type `{integer}`
...
LL | foo!(1, ~);
| ----------
| | |
| | unexpected argument of type `{integer}`
| | unexpected argument #1 of type `{integer}`
| in this macro invocation
|
note: function defined here
Expand All @@ -290,12 +290,12 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:14:9
|
LL | empty(1, $y);
| ^^^^^ - unexpected argument of type `{integer}`
| ^^^^^ - unexpected argument #1 of type `{integer}`
...
LL | foo!(~, 1);
| ----------
| | |
| | unexpected argument of type `{integer}`
| | unexpected argument #2 of type `{integer}`
| in this macro invocation
|
note: function defined here
Expand All @@ -314,8 +314,8 @@ LL | empty($x, $y);
LL | foo!(1, 1);
| ----------
| | | |
| | | unexpected argument of type `{integer}`
| | unexpected argument of type `{integer}`
| | | unexpected argument #2 of type `{integer}`
| | unexpected argument #1 of type `{integer}`
| in this macro invocation
|
note: function defined here
Expand All @@ -329,7 +329,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:53:3
|
LL | one_arg(1, panic!());
| ^^^^^^^ -------- unexpected argument
| ^^^^^^^ -------- unexpected argument #2
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -346,7 +346,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:54:3
|
LL | one_arg(panic!(), 1);
| ^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -363,7 +363,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:55:3
|
LL | one_arg(stringify!($e), 1);
| ^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand All @@ -380,7 +380,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:60:3
|
LL | one_arg(for _ in 1.. {}, 1);
| ^^^^^^^ - unexpected argument of type `{integer}`
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/argument-suggestions/issue-100478.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ error[E0061]: this function takes 3 arguments but 1 argument was supplied
LL | three_diff(T2::new(0));
| ^^^^^^^^^^------------
| ||
| |an argument of type `T1` is missing
| an argument of type `T3` is missing
| |argument #1 of type `T1` is missing
| argument #3 of type `T3` is missing
|
note: function defined here
--> $DIR/issue-100478.rs:30:4
Expand Down Expand Up @@ -63,7 +63,7 @@ LL | foo(
| ^^^
...
LL | p3, p4, p5, p6, p7, p8,
| -- an argument of type `Arc<T2>` is missing
| -- argument #2 of type `Arc<T2>` is missing
|
note: function defined here
--> $DIR/issue-100478.rs:29:4
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/argument-suggestions/issue-101097.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0061]: this function takes 6 arguments but 7 arguments were supplied
LL | f(C, A, A, A, B, B, C);
| ^ - - - - expected `C`, found `B`
| | | |
| | | unexpected argument of type `A`
| | | unexpected argument #4 of type `A`
| | expected `B`, found `A`
| expected `A`, found `C`
|
Expand Down Expand Up @@ -64,8 +64,8 @@ error[E0308]: arguments to this function are incorrect
LL | f(A, A, D, D, B, B);
| ^ - - ---- two arguments of type `C` and `C` are missing
| | |
| | unexpected argument of type `D`
| unexpected argument of type `D`
| | unexpected argument #4 of type `D`
| unexpected argument #3 of type `D`
|
note: function defined here
--> $DIR/issue-101097.rs:6:4
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/argument-suggestions/issue-109425.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/issue-109425.rs:10:5
|
LL | f(0, 1,); // f()
| ^ - - unexpected argument of type `{integer}`
| ^ - - unexpected argument #2 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #1 of type `{integer}`
|
note: function defined here
--> $DIR/issue-109425.rs:3:4
Expand All @@ -21,9 +21,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
--> $DIR/issue-109425.rs:12:5
|
LL | i(0, 1, 2,); // i(0,)
| ^ - - unexpected argument of type `{integer}`
| ^ - - unexpected argument #3 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/issue-109425.rs:4:4
Expand All @@ -40,9 +40,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
--> $DIR/issue-109425.rs:14:5
|
LL | i(0, 1, 2); // i(0)
| ^ - - unexpected argument of type `{integer}`
| ^ - - unexpected argument #3 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/issue-109425.rs:4:4
Expand All @@ -59,9 +59,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
--> $DIR/issue-109425.rs:16:5
|
LL | is(0, 1, 2, ""); // is(0, "")
| ^^ - - unexpected argument of type `{integer}`
| ^^ - - unexpected argument #3 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #2 of type `{integer}`
|
note: function defined here
--> $DIR/issue-109425.rs:5:4
Expand All @@ -78,9 +78,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
--> $DIR/issue-109425.rs:18:5
|
LL | s(0, 1, ""); // s("")
| ^ - - unexpected argument of type `{integer}`
| ^ - - unexpected argument #2 of type `{integer}`
| |
| unexpected argument of type `{integer}`
| unexpected argument #1 of type `{integer}`
|
note: function defined here
--> $DIR/issue-109425.rs:6:4
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/argument-suggestions/issue-109831.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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
| ^ - - - unexpected argument #4
| | |
| | expected `B`, found `A`
| expected `B`, found `A`
Expand Down
Loading
Loading