Skip to content

Commit 4c34626

Browse files
committed
Malformed call function call: do multiple suggestions when possible
1 parent 16ad385 commit 4c34626

19 files changed

+234
-169
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 145 additions & 77 deletions
Large diffs are not rendered by default.

compiler/rustc_span/src/source_map.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,13 @@ impl SourceMap {
543543
/// Extracts the source surrounding the given `Span` using the `extract_source` function. The
544544
/// extract function takes three arguments: a string slice containing the source, an index in
545545
/// the slice for the beginning of the span and an index in the slice for the end of the span.
546-
pub fn span_to_source<F, T>(&self, sp: Span, extract_source: F) -> Result<T, SpanSnippetError>
546+
pub fn span_to_source<F, T>(
547+
&self,
548+
sp: Span,
549+
mut extract_source: F,
550+
) -> Result<T, SpanSnippetError>
547551
where
548-
F: Fn(&str, usize, usize) -> Result<T, SpanSnippetError>,
552+
F: FnMut(&str, usize, usize) -> Result<T, SpanSnippetError>,
549553
{
550554
let local_begin = self.lookup_byte_offset(sp.lo());
551555
let local_end = self.lookup_byte_offset(sp.hi());
@@ -700,7 +704,7 @@ impl SourceMap {
700704
pub fn span_extend_while(
701705
&self,
702706
span: Span,
703-
f: impl Fn(char) -> bool,
707+
mut f: impl FnMut(char) -> bool,
704708
) -> Result<Span, SpanSnippetError> {
705709
self.span_to_source(span, |s, _start, end| {
706710
let n = s[end..].char_indices().find(|&(_, c)| !f(c)).map_or(s.len() - end, |(i, _)| i);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ LL | fn dstfn(src: i32, dst: err);
1717
| ^^^^^ ---
1818
help: provide the argument
1919
|
20-
LL | dstfn(1, /* dst */);
21-
| +++++++++++
20+
LL - dstfn(1);
21+
LL + dstfn(/* dst */);
22+
|
2223

2324
error: aborting due to 2 previous errors
2425

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | fn three_diff(_a: T1, _b: T2, _c: T3) {}
1515
help: provide the arguments
1616
|
1717
LL - three_diff(T2::new(0));
18-
LL + three_diff(/* T1 */, T2::new(0), /* T3 */);
18+
LL + three_diff(/* T1 */, /* T3 */);
1919
|
2020

2121
error[E0308]: arguments to this function are incorrect
@@ -75,16 +75,8 @@ LL | fn foo(p1: T1, p2: Arc<T2>, p3: T3, p4: Arc<T4>, p5: T5, p6: T6, p7: T7, p8
7575
| ^^^ -----------
7676
help: provide the argument
7777
|
78-
LL ~ foo(
79-
LL + p1,
80-
LL + /* Arc<T2> */,
81-
LL + p3,
82-
LL + p4,
83-
LL + p5,
84-
LL + p6,
85-
LL + p7,
86-
LL + p8,
87-
LL ~ );
78+
LL - p1, //p2,
79+
LL + /* Arc<T2> */
8880
|
8981

9082
error: aborting due to 4 previous errors

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ LL | pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
1111
| ^ -------- -------- -------- --------
1212
help: provide the arguments
1313
|
14-
LL | g((), /* bool */, /* bool */, /* bool */, /* bool */, ());
15-
| +++++++++++++++++++++++++++++++++++++++++++++++
14+
LL - g((), ());
15+
LL + g(/* bool */, /* bool */, /* bool */, /* bool */, , ());
16+
|
1617

1718
error: aborting due to 1 previous error
1819

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ LL | (|_, ()| ())(if true {} else {return;});
1111
| ^^^^^^^
1212
help: provide the argument
1313
|
14-
LL | (|_, ()| ())(if true {} else {return;}, ());
15-
| ++++
14+
LL - (|_, ()| ())(if true {} else {return;});
15+
LL + (|_, ()| ())(());
16+
|
1617

1718
error: aborting due to 1 previous error
1819

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ LL | (|_, ()| ())([return, ()]);
1111
| ^^^^^^^
1212
help: provide the argument
1313
|
14-
LL | (|_, ()| ())([return, ()], ());
15-
| ++++
14+
LL - (|_, ()| ())([return, ()]);
15+
LL + (|_, ()| ())(());
16+
|
1617

1718
error: aborting due to 1 previous error
1819

tests/ui/argument-suggestions/missing_arguments.stderr

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ LL | fn two_same(_a: i32, _b: i32) {}
2727
| ^^^^^^^^ ------- -------
2828
help: provide the arguments
2929
|
30-
LL - two_same( );
31-
LL + two_same(/* i32 */, /* i32 */);
32-
|
30+
LL | two_same(/* i32 */, /* i32 */ );
31+
| ++++++++++++++++++++
3332

3433
error[E0061]: this function takes 2 arguments but 1 argument was supplied
3534
--> $DIR/missing_arguments.rs:15:3
@@ -45,7 +44,7 @@ LL | fn two_same(_a: i32, _b: i32) {}
4544
help: provide the argument
4645
|
4746
LL - two_same( 1 );
48-
LL + two_same(1, /* i32 */);
47+
LL + two_same( /* i32 */ );
4948
|
5049

5150
error[E0061]: this function takes 2 arguments but 0 arguments were supplied
@@ -61,9 +60,8 @@ LL | fn two_diff(_a: i32, _b: f32) {}
6160
| ^^^^^^^^ ------- -------
6261
help: provide the arguments
6362
|
64-
LL - two_diff( );
65-
LL + two_diff(/* i32 */, /* f32 */);
66-
|
63+
LL | two_diff(/* i32 */, /* f32 */ );
64+
| ++++++++++++++++++++
6765

6866
error[E0061]: this function takes 2 arguments but 1 argument was supplied
6967
--> $DIR/missing_arguments.rs:17:3
@@ -79,7 +77,7 @@ LL | fn two_diff(_a: i32, _b: f32) {}
7977
help: provide the argument
8078
|
8179
LL - two_diff( 1 );
82-
LL + two_diff(1, /* f32 */);
80+
LL + two_diff( /* f32 */ );
8381
|
8482

8583
error[E0061]: this function takes 2 arguments but 1 argument was supplied
@@ -95,9 +93,8 @@ LL | fn two_diff(_a: i32, _b: f32) {}
9593
| ^^^^^^^^ -------
9694
help: provide the argument
9795
|
98-
LL - two_diff( 1.0 );
99-
LL + two_diff(/* i32 */, 1.0);
100-
|
96+
LL | two_diff(/* i32 */, 1.0 );
97+
| ++++++++++
10198

10299
error[E0061]: this function takes 3 arguments but 0 arguments were supplied
103100
--> $DIR/missing_arguments.rs:21:3
@@ -112,9 +109,8 @@ LL | fn three_same(_a: i32, _b: i32, _c: i32) {}
112109
| ^^^^^^^^^^ ------- ------- -------
113110
help: provide the arguments
114111
|
115-
LL - three_same( );
116-
LL + three_same(/* i32 */, /* i32 */, /* i32 */);
117-
|
112+
LL | three_same(/* i32 */, /* i32 */, /* i32 */ );
113+
| +++++++++++++++++++++++++++++++
118114

119115
error[E0061]: this function takes 3 arguments but 1 argument was supplied
120116
--> $DIR/missing_arguments.rs:22:3
@@ -130,7 +126,7 @@ LL | fn three_same(_a: i32, _b: i32, _c: i32) {}
130126
help: provide the arguments
131127
|
132128
LL - three_same( 1 );
133-
LL + three_same(1, /* i32 */, /* i32 */);
129+
LL + three_same( /* i32 */, /* i32 */ );
134130
|
135131

136132
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
@@ -147,7 +143,7 @@ LL | fn three_same(_a: i32, _b: i32, _c: i32) {}
147143
help: provide the argument
148144
|
149145
LL - three_same( 1, 1 );
150-
LL + three_same(1, 1, /* i32 */);
146+
LL + three_same( 1, /* i32 */ );
151147
|
152148

153149
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
@@ -163,9 +159,8 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
163159
| ^^^^^^^^^^ -------
164160
help: provide the argument
165161
|
166-
LL - three_diff( 1.0, "" );
167-
LL + three_diff(/* i32 */, 1.0, "");
168-
|
162+
LL | three_diff(/* i32 */, 1.0, "" );
163+
| ++++++++++
169164

170165
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
171166
--> $DIR/missing_arguments.rs:27:3
@@ -181,7 +176,7 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
181176
help: provide the argument
182177
|
183178
LL - three_diff( 1, "" );
184-
LL + three_diff(1, /* f32 */, "");
179+
LL + three_diff( /* f32 */, , "" );
185180
|
186181

187182
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
@@ -198,7 +193,7 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
198193
help: provide the argument
199194
|
200195
LL - three_diff( 1, 1.0 );
201-
LL + three_diff(1, 1.0, /* &str */);
196+
LL + three_diff( 1, /* &str */ );
202197
|
203198

204199
error[E0061]: this function takes 3 arguments but 1 argument was supplied
@@ -214,9 +209,8 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
214209
| ^^^^^^^^^^ ------- -------
215210
help: provide the arguments
216211
|
217-
LL - three_diff( "" );
218-
LL + three_diff(/* i32 */, /* f32 */, "");
219-
|
212+
LL | three_diff(/* i32 */, /* f32 */, "" );
213+
| +++++++++++++++++++++
220214

221215
error[E0061]: this function takes 3 arguments but 1 argument was supplied
222216
--> $DIR/missing_arguments.rs:30:3
@@ -235,7 +229,7 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
235229
help: provide the arguments
236230
|
237231
LL - three_diff( 1.0 );
238-
LL + three_diff(/* i32 */, 1.0, /* &str */);
232+
LL + three_diff(/* i32 */, /* &str */ );
239233
|
240234

241235
error[E0061]: this function takes 3 arguments but 1 argument was supplied
@@ -252,7 +246,7 @@ LL | fn three_diff(_a: i32, _b: f32, _c: &str) {}
252246
help: provide the arguments
253247
|
254248
LL - three_diff( 1 );
255-
LL + three_diff(1, /* f32 */, /* &str */);
249+
LL + three_diff( /* f32 */, /* &str */ );
256250
|
257251

258252
error[E0061]: this function takes 4 arguments but 0 arguments were supplied
@@ -268,9 +262,8 @@ LL | fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {}
268262
| ^^^^^^^^^^^^^ ------- ------- ------- --------
269263
help: provide the arguments
270264
|
271-
LL - four_repeated( );
272-
LL + four_repeated(/* i32 */, /* f32 */, /* f32 */, /* &str */);
273-
|
265+
LL | four_repeated(/* i32 */, /* f32 */, /* f32 */, /* &str */ );
266+
| +++++++++++++++++++++++++++++++++++++++++++
274267

275268
error[E0061]: this function takes 4 arguments but 2 arguments were supplied
276269
--> $DIR/missing_arguments.rs:35:3
@@ -286,7 +279,7 @@ LL | fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {}
286279
help: provide the arguments
287280
|
288281
LL - four_repeated( 1, "" );
289-
LL + four_repeated(1, /* f32 */, /* f32 */, "");
282+
LL + four_repeated( /* f32 */, /* f32 */, , "" );
290283
|
291284

292285
error[E0061]: this function takes 5 arguments but 0 arguments were supplied
@@ -302,9 +295,8 @@ LL | fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {}
302295
| ^^^^^^^ ------- ------- ------- ------- --------
303296
help: provide the arguments
304297
|
305-
LL - complex( );
306-
LL + complex(/* i32 */, /* f32 */, /* i32 */, /* f32 */, /* &str */);
307-
|
298+
LL | complex(/* i32 */, /* f32 */, /* i32 */, /* f32 */, /* &str */ );
299+
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++
308300

309301
error[E0061]: this function takes 5 arguments but 2 arguments were supplied
310302
--> $DIR/missing_arguments.rs:39:3
@@ -320,7 +312,7 @@ LL | fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {}
320312
help: provide the arguments
321313
|
322314
LL - complex( 1, "" );
323-
LL + complex(1, /* f32 */, /* i32 */, /* f32 */, "");
315+
LL + complex( /* f32 */, /* i32 */, /* f32 */, , "" );
324316
|
325317

326318
error: aborting due to 19 previous errors

tests/ui/c-variadic/variadic-ffi-1.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ LL | fn foo(f: isize, x: u8, ...);
3939
| ^^^ -
4040
help: provide the argument
4141
|
42-
LL | foo(1, /* u8 */);
43-
| ++++++++++
42+
LL - foo(1);
43+
LL + foo(/* u8 */);
44+
|
4445

4546
error[E0308]: mismatched types
4647
--> $DIR/variadic-ffi-1.rs:31:56

tests/ui/cast/ice-cast-type-with-error-124848.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
5555
| ^^^^^^
5656
help: provide the argument
5757
|
58-
LL | let mut unpinned = MyType(Cell::new(None), /* value */);
59-
| +++++++++++++
58+
LL - let mut unpinned = MyType(Cell::new(None));
59+
LL + let mut unpinned = MyType(/* value */);
60+
|
6061

6162
error[E0606]: casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
6263
--> $DIR/ice-cast-type-with-error-124848.rs:14:20

0 commit comments

Comments
 (0)