Skip to content

Commit 53ced6f

Browse files
authored
Unrolled build for rust-lang#125042
Rollup merge of rust-lang#125042 - long-long-float:suggest-move-arg-outside, r=fmease Use ordinal number in argument error Add an ordinal number to two argument errors ("unexpected" and "missing") for ease of understanding error. ``` error[E0061]: this function takes 3 arguments but 2 arguments were supplied --> test.rs:11:5 | 11 | f(42, 'a'); | ^ --- 2nd argument of type `f32` is missing | (snip) error[E0061]: this function takes 3 arguments but 4 arguments were supplied --> test.rs:12:5 | 12 | f(42, 42, 1.0, 'a'); | ^ ---- | | | | | unexpected 2nd argument of type `{integer}` | help: remove the extra argument ``` To get an ordinal number, I copied `ordinalize` from other crate `rustc_resolve` because I think it is too much to link `rustc_resolve` for this small function. Please let me know if there is a better way.
2 parents fcc325f + 332b41d commit 53ced6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+151
-137
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11051105
} else {
11061106
"".to_string()
11071107
};
1108-
labels.push((provided_span, format!("unexpected argument{provided_ty_name}")));
1108+
let idx = if provided_arg_tys.len() == 1 {
1109+
"".to_string()
1110+
} else {
1111+
format!(" #{}", arg_idx.as_usize() + 1)
1112+
};
1113+
labels.push((
1114+
provided_span,
1115+
format!("unexpected argument{idx}{provided_ty_name}"),
1116+
));
11091117
let mut span = provided_span;
11101118
if span.can_be_used_for_suggestions()
11111119
&& error_span.can_be_used_for_suggestions()
@@ -1186,7 +1194,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11861194
} else {
11871195
"".to_string()
11881196
};
1189-
labels.push((span, format!("an argument{rendered} is missing")));
1197+
labels.push((
1198+
span,
1199+
format!(
1200+
"argument #{}{rendered} is missing",
1201+
expected_idx.as_usize() + 1
1202+
),
1203+
));
1204+
11901205
suggestion_text = match suggestion_text {
11911206
SuggestionText::None => SuggestionText::Provide(false),
11921207
SuggestionText::Provide(_) => SuggestionText::Provide(true),

tests/ui/argument-suggestions/basic.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied
3333
--> $DIR/basic.rs:22:5
3434
|
3535
LL | missing();
36-
| ^^^^^^^-- an argument of type `u32` is missing
36+
| ^^^^^^^-- argument #1 of type `u32` is missing
3737
|
3838
note: function defined here
3939
--> $DIR/basic.rs:15:4
@@ -86,7 +86,7 @@ error[E0057]: this function takes 1 argument but 0 arguments were supplied
8686
--> $DIR/basic.rs:27:5
8787
|
8888
LL | closure();
89-
| ^^^^^^^-- an argument is missing
89+
| ^^^^^^^-- argument #1 is missing
9090
|
9191
note: closure defined here
9292
--> $DIR/basic.rs:26:19

tests/ui/argument-suggestions/display-is-suggestable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0061]: this function takes 1 argument but 0 arguments were supplied
22
--> $DIR/display-is-suggestable.rs:6:5
33
|
44
LL | foo();
5-
| ^^^-- an argument of type `&dyn std::fmt::Display + Send` is missing
5+
| ^^^-- argument #1 of type `&dyn std::fmt::Display + Send` is missing
66
|
77
note: function defined here
88
--> $DIR/display-is-suggestable.rs:3:4

tests/ui/argument-suggestions/extern-fn-arg-names.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0061]: this function takes 2 arguments but 1 argument was supplied
88
--> $DIR/extern-fn-arg-names.rs:7:5
99
|
1010
LL | dstfn(1);
11-
| ^^^^^--- an argument is missing
11+
| ^^^^^--- argument #2 is missing
1212
|
1313
note: function defined here
1414
--> $DIR/extern-fn-arg-names.rs:2:8

tests/ui/argument-suggestions/extra_arguments.stderr

+28-28
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
1919
--> $DIR/extra_arguments.rs:20:3
2020
|
2121
LL | empty(1, 1);
22-
| ^^^^^ - - unexpected argument of type `{integer}`
22+
| ^^^^^ - - unexpected argument #2 of type `{integer}`
2323
| |
24-
| unexpected argument of type `{integer}`
24+
| unexpected argument #1 of type `{integer}`
2525
|
2626
note: function defined here
2727
--> $DIR/extra_arguments.rs:1:4
@@ -38,7 +38,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
3838
--> $DIR/extra_arguments.rs:22:3
3939
|
4040
LL | one_arg(1, 1);
41-
| ^^^^^^^ - unexpected argument of type `{integer}`
41+
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
4242
|
4343
note: function defined here
4444
--> $DIR/extra_arguments.rs:2:4
@@ -55,7 +55,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
5555
--> $DIR/extra_arguments.rs:23:3
5656
|
5757
LL | one_arg(1, "");
58-
| ^^^^^^^ -- unexpected argument of type `&'static str`
58+
| ^^^^^^^ -- unexpected argument #2 of type `&'static str`
5959
|
6060
note: function defined here
6161
--> $DIR/extra_arguments.rs:2:4
@@ -72,9 +72,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
7272
--> $DIR/extra_arguments.rs:24:3
7373
|
7474
LL | one_arg(1, "", 1.0);
75-
| ^^^^^^^ -- --- unexpected argument of type `{float}`
75+
| ^^^^^^^ -- --- unexpected argument #3 of type `{float}`
7676
| |
77-
| unexpected argument of type `&'static str`
77+
| unexpected argument #2 of type `&'static str`
7878
|
7979
note: function defined here
8080
--> $DIR/extra_arguments.rs:2:4
@@ -91,7 +91,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
9191
--> $DIR/extra_arguments.rs:26:3
9292
|
9393
LL | two_arg_same(1, 1, 1);
94-
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
94+
| ^^^^^^^^^^^^ - unexpected argument #3 of type `{integer}`
9595
|
9696
note: function defined here
9797
--> $DIR/extra_arguments.rs:3:4
@@ -108,7 +108,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
108108
--> $DIR/extra_arguments.rs:27:3
109109
|
110110
LL | two_arg_same(1, 1, 1.0);
111-
| ^^^^^^^^^^^^ --- unexpected argument of type `{float}`
111+
| ^^^^^^^^^^^^ --- unexpected argument #3 of type `{float}`
112112
|
113113
note: function defined here
114114
--> $DIR/extra_arguments.rs:3:4
@@ -125,7 +125,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
125125
--> $DIR/extra_arguments.rs:29:3
126126
|
127127
LL | two_arg_diff(1, 1, "");
128-
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
128+
| ^^^^^^^^^^^^ - unexpected argument #2 of type `{integer}`
129129
|
130130
note: function defined here
131131
--> $DIR/extra_arguments.rs:4:4
@@ -142,7 +142,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
142142
--> $DIR/extra_arguments.rs:30:3
143143
|
144144
LL | two_arg_diff(1, "", "");
145-
| ^^^^^^^^^^^^ -- unexpected argument of type `&'static str`
145+
| ^^^^^^^^^^^^ -- unexpected argument #3 of type `&'static str`
146146
|
147147
note: function defined here
148148
--> $DIR/extra_arguments.rs:4:4
@@ -159,9 +159,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
159159
--> $DIR/extra_arguments.rs:31:3
160160
|
161161
LL | two_arg_diff(1, 1, "", "");
162-
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
162+
| ^^^^^^^^^^^^ - -- unexpected argument #4 of type `&'static str`
163163
| |
164-
| unexpected argument of type `{integer}`
164+
| unexpected argument #2 of type `{integer}`
165165
|
166166
note: function defined here
167167
--> $DIR/extra_arguments.rs:4:4
@@ -178,9 +178,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
178178
--> $DIR/extra_arguments.rs:32:3
179179
|
180180
LL | two_arg_diff(1, "", 1, "");
181-
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
181+
| ^^^^^^^^^^^^ - -- unexpected argument #4 of type `&'static str`
182182
| |
183-
| unexpected argument of type `{integer}`
183+
| unexpected argument #3 of type `{integer}`
184184
|
185185
note: function defined here
186186
--> $DIR/extra_arguments.rs:4:4
@@ -197,7 +197,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
197197
--> $DIR/extra_arguments.rs:35:3
198198
|
199199
LL | two_arg_same(1, 1, "");
200-
| ^^^^^^^^^^^^ -- unexpected argument of type `&'static str`
200+
| ^^^^^^^^^^^^ -- unexpected argument #3 of type `&'static str`
201201
|
202202
note: function defined here
203203
--> $DIR/extra_arguments.rs:3:4
@@ -214,7 +214,7 @@ error[E0061]: this function takes 2 arguments but 3 arguments were supplied
214214
--> $DIR/extra_arguments.rs:36:3
215215
|
216216
LL | two_arg_diff(1, 1, "");
217-
| ^^^^^^^^^^^^ - unexpected argument of type `{integer}`
217+
| ^^^^^^^^^^^^ - unexpected argument #2 of type `{integer}`
218218
|
219219
note: function defined here
220220
--> $DIR/extra_arguments.rs:4:4
@@ -234,7 +234,7 @@ LL | two_arg_same(
234234
| ^^^^^^^^^^^^
235235
...
236236
LL | ""
237-
| -- unexpected argument of type `&'static str`
237+
| -- unexpected argument #3 of type `&'static str`
238238
|
239239
note: function defined here
240240
--> $DIR/extra_arguments.rs:3:4
@@ -255,7 +255,7 @@ LL | two_arg_diff(
255255
| ^^^^^^^^^^^^
256256
LL | 1,
257257
LL | 1,
258-
| - unexpected argument of type `{integer}`
258+
| - unexpected argument #2 of type `{integer}`
259259
|
260260
note: function defined here
261261
--> $DIR/extra_arguments.rs:4:4
@@ -271,12 +271,12 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
271271
--> $DIR/extra_arguments.rs:8:9
272272
|
273273
LL | empty($x, 1);
274-
| ^^^^^ - unexpected argument of type `{integer}`
274+
| ^^^^^ - unexpected argument #2 of type `{integer}`
275275
...
276276
LL | foo!(1, ~);
277277
| ----------
278278
| | |
279-
| | unexpected argument of type `{integer}`
279+
| | unexpected argument #1 of type `{integer}`
280280
| in this macro invocation
281281
|
282282
note: function defined here
@@ -290,12 +290,12 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
290290
--> $DIR/extra_arguments.rs:14:9
291291
|
292292
LL | empty(1, $y);
293-
| ^^^^^ - unexpected argument of type `{integer}`
293+
| ^^^^^ - unexpected argument #1 of type `{integer}`
294294
...
295295
LL | foo!(~, 1);
296296
| ----------
297297
| | |
298-
| | unexpected argument of type `{integer}`
298+
| | unexpected argument #2 of type `{integer}`
299299
| in this macro invocation
300300
|
301301
note: function defined here
@@ -314,8 +314,8 @@ LL | empty($x, $y);
314314
LL | foo!(1, 1);
315315
| ----------
316316
| | | |
317-
| | | unexpected argument of type `{integer}`
318-
| | unexpected argument of type `{integer}`
317+
| | | unexpected argument #2 of type `{integer}`
318+
| | unexpected argument #1 of type `{integer}`
319319
| in this macro invocation
320320
|
321321
note: function defined here
@@ -329,7 +329,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
329329
--> $DIR/extra_arguments.rs:53:3
330330
|
331331
LL | one_arg(1, panic!());
332-
| ^^^^^^^ -------- unexpected argument
332+
| ^^^^^^^ -------- unexpected argument #2
333333
|
334334
note: function defined here
335335
--> $DIR/extra_arguments.rs:2:4
@@ -346,7 +346,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
346346
--> $DIR/extra_arguments.rs:54:3
347347
|
348348
LL | one_arg(panic!(), 1);
349-
| ^^^^^^^ - unexpected argument of type `{integer}`
349+
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
350350
|
351351
note: function defined here
352352
--> $DIR/extra_arguments.rs:2:4
@@ -363,7 +363,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
363363
--> $DIR/extra_arguments.rs:55:3
364364
|
365365
LL | one_arg(stringify!($e), 1);
366-
| ^^^^^^^ - unexpected argument of type `{integer}`
366+
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
367367
|
368368
note: function defined here
369369
--> $DIR/extra_arguments.rs:2:4
@@ -380,7 +380,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
380380
--> $DIR/extra_arguments.rs:60:3
381381
|
382382
LL | one_arg(for _ in 1.. {}, 1);
383-
| ^^^^^^^ - unexpected argument of type `{integer}`
383+
| ^^^^^^^ - unexpected argument #2 of type `{integer}`
384384
|
385385
note: function defined here
386386
--> $DIR/extra_arguments.rs:2:4

tests/ui/argument-suggestions/issue-100478.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0061]: this function takes 3 arguments but 1 argument was supplied
44
LL | three_diff(T2::new(0));
55
| ^^^^^^^^^^------------
66
| ||
7-
| |an argument of type `T1` is missing
8-
| an argument of type `T3` is missing
7+
| |argument #1 of type `T1` is missing
8+
| argument #3 of type `T3` is missing
99
|
1010
note: function defined here
1111
--> $DIR/issue-100478.rs:30:4
@@ -63,7 +63,7 @@ LL | foo(
6363
| ^^^
6464
...
6565
LL | p3, p4, p5, p6, p7, p8,
66-
| -- an argument of type `Arc<T2>` is missing
66+
| -- argument #2 of type `Arc<T2>` is missing
6767
|
6868
note: function defined here
6969
--> $DIR/issue-100478.rs:29:4

tests/ui/argument-suggestions/issue-101097.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0061]: this function takes 6 arguments but 7 arguments were supplied
44
LL | f(C, A, A, A, B, B, C);
55
| ^ - - - - expected `C`, found `B`
66
| | | |
7-
| | | unexpected argument of type `A`
7+
| | | unexpected argument #4 of type `A`
88
| | expected `B`, found `A`
99
| expected `A`, found `C`
1010
|
@@ -64,8 +64,8 @@ error[E0308]: arguments to this function are incorrect
6464
LL | f(A, A, D, D, B, B);
6565
| ^ - - ---- two arguments of type `C` and `C` are missing
6666
| | |
67-
| | unexpected argument of type `D`
68-
| unexpected argument of type `D`
67+
| | unexpected argument #4 of type `D`
68+
| unexpected argument #3 of type `D`
6969
|
7070
note: function defined here
7171
--> $DIR/issue-101097.rs:6:4

tests/ui/argument-suggestions/issue-109425.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
22
--> $DIR/issue-109425.rs:10:5
33
|
44
LL | f(0, 1,); // f()
5-
| ^ - - unexpected argument of type `{integer}`
5+
| ^ - - unexpected argument #2 of type `{integer}`
66
| |
7-
| unexpected argument of type `{integer}`
7+
| unexpected argument #1 of type `{integer}`
88
|
99
note: function defined here
1010
--> $DIR/issue-109425.rs:3:4
@@ -21,9 +21,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
2121
--> $DIR/issue-109425.rs:12:5
2222
|
2323
LL | i(0, 1, 2,); // i(0,)
24-
| ^ - - unexpected argument of type `{integer}`
24+
| ^ - - unexpected argument #3 of type `{integer}`
2525
| |
26-
| unexpected argument of type `{integer}`
26+
| unexpected argument #2 of type `{integer}`
2727
|
2828
note: function defined here
2929
--> $DIR/issue-109425.rs:4:4
@@ -40,9 +40,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
4040
--> $DIR/issue-109425.rs:14:5
4141
|
4242
LL | i(0, 1, 2); // i(0)
43-
| ^ - - unexpected argument of type `{integer}`
43+
| ^ - - unexpected argument #3 of type `{integer}`
4444
| |
45-
| unexpected argument of type `{integer}`
45+
| unexpected argument #2 of type `{integer}`
4646
|
4747
note: function defined here
4848
--> $DIR/issue-109425.rs:4:4
@@ -59,9 +59,9 @@ error[E0061]: this function takes 2 arguments but 4 arguments were supplied
5959
--> $DIR/issue-109425.rs:16:5
6060
|
6161
LL | is(0, 1, 2, ""); // is(0, "")
62-
| ^^ - - unexpected argument of type `{integer}`
62+
| ^^ - - unexpected argument #3 of type `{integer}`
6363
| |
64-
| unexpected argument of type `{integer}`
64+
| unexpected argument #2 of type `{integer}`
6565
|
6666
note: function defined here
6767
--> $DIR/issue-109425.rs:5:4
@@ -78,9 +78,9 @@ error[E0061]: this function takes 1 argument but 3 arguments were supplied
7878
--> $DIR/issue-109425.rs:18:5
7979
|
8080
LL | s(0, 1, ""); // s("")
81-
| ^ - - unexpected argument of type `{integer}`
81+
| ^ - - unexpected argument #2 of type `{integer}`
8282
| |
83-
| unexpected argument of type `{integer}`
83+
| unexpected argument #1 of type `{integer}`
8484
|
8585
note: function defined here
8686
--> $DIR/issue-109425.rs:6:4

tests/ui/argument-suggestions/issue-109831.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error[E0061]: this function takes 3 arguments but 4 arguments were supplied
2929
--> $DIR/issue-109831.rs:7:5
3030
|
3131
LL | f(A, A, B, C);
32-
| ^ - - - unexpected argument
32+
| ^ - - - unexpected argument #4
3333
| | |
3434
| | expected `B`, found `A`
3535
| expected `B`, found `A`

0 commit comments

Comments
 (0)