Skip to content

Commit 7bbed3e

Browse files
Rollup merge of #106478 - estebank:tweak-fn-mismatch, r=compiler-errors
Tweak wording of fn call with wrong number of args
2 parents fea926c + 5393c6b commit 7bbed3e

File tree

64 files changed

+143
-146
lines changed

Some content is hidden

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

64 files changed

+143
-146
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -473,38 +473,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473473
call_expr: &hir::Expr<'tcx>,
474474
) {
475475
// Next, let's construct the error
476-
let (error_span, full_call_span, ctor_of, is_method) = match &call_expr.kind {
476+
let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind {
477477
hir::ExprKind::Call(
478478
hir::Expr { hir_id, span, kind: hir::ExprKind::Path(qpath), .. },
479479
_,
480480
) => {
481481
if let Res::Def(DefKind::Ctor(of, _), _) =
482482
self.typeck_results.borrow().qpath_res(qpath, *hir_id)
483483
{
484-
(call_span, *span, Some(of), false)
484+
let name = match of {
485+
CtorOf::Struct => "struct",
486+
CtorOf::Variant => "enum variant",
487+
};
488+
(call_span, *span, name, false)
485489
} else {
486-
(call_span, *span, None, false)
490+
(call_span, *span, "function", false)
487491
}
488492
}
489-
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None, false),
493+
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, "function", false),
490494
hir::ExprKind::MethodCall(path_segment, _, _, span) => {
491495
let ident_span = path_segment.ident.span;
492496
let ident_span = if let Some(args) = path_segment.args {
493497
ident_span.with_hi(args.span_ext.hi())
494498
} else {
495499
ident_span
496500
};
497-
// methods are never ctors
498-
(*span, ident_span, None, true)
501+
(*span, ident_span, "method", true)
499502
}
500503
k => span_bug!(call_span, "checking argument types on a non-call: `{:?}`", k),
501504
};
502505
let args_span = error_span.trim_start(full_call_span).unwrap_or(error_span);
503-
let call_name = match ctor_of {
504-
Some(CtorOf::Struct) => "struct",
505-
Some(CtorOf::Variant) => "enum variant",
506-
None => "function",
507-
};
508506

509507
// Don't print if it has error types or is just plain `_`
510508
fn has_error_or_infer<'tcx>(tys: impl IntoIterator<Item = Ty<'tcx>>) -> bool {
@@ -690,8 +688,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
690688
err = tcx.sess.struct_span_err_with_code(
691689
full_call_span,
692690
&format!(
693-
"this {} takes {}{} but {} {} supplied",
694-
call_name,
691+
"{call_name} takes {}{} but {} {} supplied",
695692
if c_variadic { "at least " } else { "" },
696693
potentially_plural_count(
697694
formal_and_expected_inputs.len(),

src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
struct Layout;
88

99
#[alloc_error_handler]
10-
fn oom() -> ! { //~ ERROR this function takes 0 arguments but 1 argument was supplied
10+
fn oom() -> ! { //~ ERROR function takes 0 arguments but 1 argument was supplied
1111
loop {}
1212
}
1313

src/test/ui/argument-suggestions/basic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ fn permuted(_x: X, _y: Y, _z: Z) {}
1818

1919
fn main() {
2020
invalid(1.0); //~ ERROR mismatched types
21-
extra(""); //~ ERROR this function takes
22-
missing(); //~ ERROR this function takes
21+
extra(""); //~ ERROR function takes
22+
missing(); //~ ERROR function takes
2323
swapped("", 1); //~ ERROR arguments to this function are incorrect
2424
permuted(Y {}, Z {}, X {}); //~ ERROR arguments to this function are incorrect
2525

2626
let closure = |x| x;
27-
closure(); //~ ERROR this function takes
27+
closure(); //~ ERROR function takes
2828
}

src/test/ui/argument-suggestions/display-is-suggestable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn foo(x: &(dyn Display + Send)) {}
44

55
fn main() {
66
foo();
7-
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
7+
//~^ ERROR function takes 1 argument but 0 arguments were supplied
88
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
fn foo<T: Fn()>(t: T) {
22
t(1i32);
3-
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
3+
//~^ ERROR function takes 0 arguments but 1 argument was supplied
44
}
55

66
fn bar(t: impl Fn()) {
77
t(1i32);
8-
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
8+
//~^ ERROR function takes 0 arguments but 1 argument was supplied
99
}
1010

1111
fn baz() -> impl Fn() {
@@ -14,13 +14,13 @@ fn baz() -> impl Fn() {
1414

1515
fn baz2() {
1616
baz()(1i32)
17-
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
17+
//~^ ERROR function takes 0 arguments but 1 argument was supplied
1818
}
1919

2020
fn qux() {
2121
let x = || {};
2222
x(1i32);
23-
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
23+
//~^ ERROR function takes 0 arguments but 1 argument was supplied
2424
}
2525

2626
fn main() {}

src/test/ui/argument-suggestions/extern-fn-arg-names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ extern "Rust" {
55

66
fn main() {
77
dstfn(1);
8-
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
8+
//~^ ERROR function takes 2 arguments but 1 argument was supplied
99
}

src/test/ui/argument-suggestions/extra_arguments.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ fn two_arg_same(_a: i32, _b: i32) {}
44
fn two_arg_diff(_a: i32, _b: &str) {}
55

66
fn main() {
7-
empty(""); //~ ERROR this function takes
7+
empty(""); //~ ERROR function takes
88

9-
one_arg(1, 1); //~ ERROR this function takes
10-
one_arg(1, ""); //~ ERROR this function takes
11-
one_arg(1, "", 1.0); //~ ERROR this function takes
9+
one_arg(1, 1); //~ ERROR function takes
10+
one_arg(1, ""); //~ ERROR function takes
11+
one_arg(1, "", 1.0); //~ ERROR function takes
1212

13-
two_arg_same(1, 1, 1); //~ ERROR this function takes
14-
two_arg_same(1, 1, 1.0); //~ ERROR this function takes
13+
two_arg_same(1, 1, 1); //~ ERROR function takes
14+
two_arg_same(1, 1, 1.0); //~ ERROR function takes
1515

16-
two_arg_diff(1, 1, ""); //~ ERROR this function takes
17-
two_arg_diff(1, "", ""); //~ ERROR this function takes
18-
two_arg_diff(1, 1, "", ""); //~ ERROR this function takes
19-
two_arg_diff(1, "", 1, ""); //~ ERROR this function takes
16+
two_arg_diff(1, 1, ""); //~ ERROR function takes
17+
two_arg_diff(1, "", ""); //~ ERROR function takes
18+
two_arg_diff(1, 1, "", ""); //~ ERROR function takes
19+
two_arg_diff(1, "", 1, ""); //~ ERROR function takes
2020

2121
// Check with weird spacing and newlines
22-
two_arg_same(1, 1, ""); //~ ERROR this function takes
23-
two_arg_diff(1, 1, ""); //~ ERROR this function takes
24-
two_arg_same( //~ ERROR this function takes
22+
two_arg_same(1, 1, ""); //~ ERROR function takes
23+
two_arg_diff(1, 1, ""); //~ ERROR function takes
24+
two_arg_same( //~ ERROR function takes
2525
1,
2626
1,
2727
""
2828
);
2929

30-
two_arg_diff( //~ ERROR this function takes
30+
two_arg_diff( //~ ERROR function takes
3131
1,
3232
1,
3333
""

src/test/ui/argument-suggestions/issue-100154.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ fn foo(i: impl std::fmt::Display) {}
22

33
fn main() {
44
foo::<()>(());
5-
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
5+
//~^ ERROR function takes 0 generic arguments but 1 generic argument was supplied
66
//~| ERROR `()` doesn't implement `std::fmt::Display`
77
}

src/test/ui/argument-suggestions/issue-100478.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn three_diff(_a: T1, _b: T2, _c: T3) {}
3131
fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {}
3232

3333
fn main() {
34-
three_diff(T2::new(0)); //~ ERROR this function takes
34+
three_diff(T2::new(0)); //~ ERROR function takes
3535
four_shuffle(T3::default(), T4::default(), T1::default(), T2::default()); //~ ERROR 35:5: 35:17: arguments to this function are incorrect [E0308]
3636
four_shuffle(T3::default(), T2::default(), T1::default(), T3::default()); //~ ERROR 36:5: 36:17: arguments to this function are incorrect [E0308]
3737

src/test/ui/argument-suggestions/issue-101097.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn f(
1313
) {}
1414

1515
fn main() {
16-
f(C, A, A, A, B, B, C); //~ ERROR this function takes 6 arguments but 7 arguments were supplied [E0061]
16+
f(C, A, A, A, B, B, C); //~ ERROR function takes 6 arguments but 7 arguments were supplied [E0061]
1717
f(C, C, A, A, B, B); //~ ERROR arguments to this function are incorrect [E0308]
1818
f(A, A, D, D, B, B); //~ arguments to this function are incorrect [E0308]
1919
f(C, C, B, B, A, A); //~ arguments to this function are incorrect [E0308]

src/test/ui/argument-suggestions/issue-96638.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ fn arg<T>() -> T { todo!() }
55
fn main() {
66
let x = arg(); // `x` must be inferred
77
// The reference on `&x` is important to reproduce the ICE
8-
f(&x, ""); //~ ERROR this function takes 3 arguments but 2 arguments were supplied
8+
f(&x, ""); //~ ERROR function takes 3 arguments but 2 arguments were supplied
99
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
g((), ());
3-
//~^ ERROR this function takes 6 arguments but 2 arguments were supplied
3+
//~^ ERROR function takes 6 arguments but 2 arguments were supplied
44
}
55

66
pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}

src/test/ui/argument-suggestions/issue-97484.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ fn foo(a: &A, d: D, e: &E, g: G) {}
1010

1111
fn main() {
1212
foo(&&A, B, C, D, E, F, G);
13-
//~^ ERROR this function takes 4 arguments but 7 arguments were supplied
13+
//~^ ERROR function takes 4 arguments but 7 arguments were supplied
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
(|_, ()| ())(if true {} else {return;});
3-
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
3+
//~^ ERROR function takes 2 arguments but 1 argument was supplied
44
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
(|_, ()| ())([return, ()]);
3-
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
3+
//~^ ERROR function takes 2 arguments but 1 argument was supplied
44
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
22
let f = |_: (), f: fn()| f;
33
let _f = f(main);
4-
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
//~^ ERROR function takes 2 arguments but 1 argument was supplied
55
}

src/test/ui/argument-suggestions/missing_arguments.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@ fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {}
77
fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {}
88

99
fn main() {
10-
one_arg(); //~ ERROR this function takes
10+
one_arg(); //~ ERROR function takes
1111
// The headers here show the types expected,
1212
// with formatting to emphasize which arguments are missing
1313
/* i32 f32 */
14-
two_same( ); //~ ERROR this function takes
15-
two_same( 1 ); //~ ERROR this function takes
16-
two_diff( ); //~ ERROR this function takes
17-
two_diff( 1 ); //~ ERROR this function takes
18-
two_diff( 1.0 ); //~ ERROR this function takes
14+
two_same( ); //~ ERROR function takes
15+
two_same( 1 ); //~ ERROR function takes
16+
two_diff( ); //~ ERROR function takes
17+
two_diff( 1 ); //~ ERROR function takes
18+
two_diff( 1.0 ); //~ ERROR function takes
1919

2020
/* i32 i32 i32 */
21-
three_same( ); //~ ERROR this function takes
22-
three_same( 1 ); //~ ERROR this function takes
23-
three_same( 1, 1 ); //~ ERROR this function takes
21+
three_same( ); //~ ERROR function takes
22+
three_same( 1 ); //~ ERROR function takes
23+
three_same( 1, 1 ); //~ ERROR function takes
2424

2525
/* i32 f32 &str */
26-
three_diff( 1.0, "" ); //~ ERROR this function takes
27-
three_diff( 1, "" ); //~ ERROR this function takes
28-
three_diff( 1, 1.0 ); //~ ERROR this function takes
29-
three_diff( "" ); //~ ERROR this function takes
30-
three_diff( 1.0 ); //~ ERROR this function takes
31-
three_diff( 1 ); //~ ERROR this function takes
26+
three_diff( 1.0, "" ); //~ ERROR function takes
27+
three_diff( 1, "" ); //~ ERROR function takes
28+
three_diff( 1, 1.0 ); //~ ERROR function takes
29+
three_diff( "" ); //~ ERROR function takes
30+
three_diff( 1.0 ); //~ ERROR function takes
31+
three_diff( 1 ); //~ ERROR function takes
3232

3333
/* i32 f32 f32 &str */
34-
four_repeated( ); //~ ERROR this function takes
35-
four_repeated( 1, "" ); //~ ERROR this function takes
34+
four_repeated( ); //~ ERROR function takes
35+
four_repeated( 1, "" ); //~ ERROR function takes
3636

3737
/* i32 f32 i32 f32 &str */
38-
complex( ); //~ ERROR this function takes
39-
complex( 1, "" ); //~ ERROR this function takes
38+
complex( ); //~ ERROR function takes
39+
complex( 1, "" ); //~ ERROR function takes
4040
}

src/test/ui/argument-suggestions/mixed_cases.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ fn three_args(_a: i32, _b: f32, _c: &str) {}
77

88
fn main() {
99
// Extra + Invalid
10-
two_args(1, "", X {}); //~ ERROR this function takes
11-
three_args(1, "", X {}, ""); //~ ERROR this function takes
10+
two_args(1, "", X {}); //~ ERROR function takes
11+
three_args(1, "", X {}, ""); //~ ERROR function takes
1212

1313
// Missing and Invalid
14-
three_args(1, X {}); //~ ERROR this function takes
14+
three_args(1, X {}); //~ ERROR function takes
1515

1616
// Missing and Extra
1717
three_args(1, "", X {}); //~ ERROR arguments to this function are incorrect
@@ -20,5 +20,5 @@ fn main() {
2020
three_args("", X {}, 1); //~ ERROR arguments to this function are incorrect
2121

2222
// Swapped and missing
23-
three_args("", 1); //~ ERROR this function takes
23+
three_args("", 1); //~ ERROR function takes
2424
}

src/test/ui/argument-suggestions/too-long.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44
LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l);
55
| --- ^ expected `i32`, found `&i32`
66
| |
7-
| arguments to this function are incorrect
7+
| arguments to this method are incorrect
88
|
99
note: associated function defined here
1010
--> $DIR/too-long.rs:4:8

src/test/ui/associated-types/associated-type-projection-from-supertrait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error[E0308]: mismatched types
3232
LL | fn f() { ModelT.chip_paint(Blue); }
3333
| ---------- ^^^^ expected struct `Black`, found struct `Blue`
3434
| |
35-
| arguments to this function are incorrect
35+
| arguments to this method are incorrect
3636
|
3737
note: associated function defined here
3838
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
@@ -46,7 +46,7 @@ error[E0308]: mismatched types
4646
LL | fn g() { ModelU.chip_paint(Black); }
4747
| ---------- ^^^^^ expected struct `Blue`, found struct `Black`
4848
| |
49-
| arguments to this function are incorrect
49+
| arguments to this method are incorrect
5050
|
5151
note: associated function defined here
5252
--> $DIR/associated-type-projection-from-supertrait.rs:12:8

src/test/ui/c-variadic/variadic-ffi-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extern "C" fn bar(f: isize, x: u8) {}
1919

2020
fn main() {
2121
unsafe {
22-
foo(); //~ ERROR this function takes at least 2 arguments but 0 arguments were supplied
23-
foo(1); //~ ERROR this function takes at least 2 arguments but 1 argument was supplied
22+
foo(); //~ ERROR function takes at least 2 arguments but 0 arguments were supplied
23+
foo(1); //~ ERROR function takes at least 2 arguments but 1 argument was supplied
2424

2525
let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~ ERROR mismatched types
2626
let y: extern "C" fn(f: isize, x: u8, ...) = bar; //~ ERROR mismatched types

src/test/ui/const-generics/generic_const_exprs/issue-76595.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
1313

1414
fn main() {
1515
test::<2>();
16-
//~^ ERROR this function takes 2 generic arguments
16+
//~^ ERROR function takes 2 generic arguments
1717
}

src/test/ui/const-generics/incorrect-number-of-const-args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ fn foo<const X: usize, const Y: usize>() -> usize {
44

55
fn main() {
66
foo::<0>();
7-
//~^ ERROR this function takes 2
7+
//~^ ERROR function takes 2
88

99
foo::<0, 0, 0>();
10-
//~^ ERROR this function takes 2
10+
//~^ ERROR function takes 2
1111
}

src/test/ui/fn/issue-3044.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
let needlesArr: Vec<char> = vec!['a', 'f'];
33
needlesArr.iter().fold(|x, y| {
4-
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
4+
//~^ ERROR this method takes 2 arguments but 1 argument was supplied
55
});
66
}

src/test/ui/fn/issue-3044.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0061]: this function takes 2 arguments but 1 argument was supplied
1+
error[E0061]: this method takes 2 arguments but 1 argument was supplied
22
--> $DIR/issue-3044.rs:3:23
33
|
44
LL | needlesArr.iter().fold(|x, y| {

src/test/ui/generator/issue-102645.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
a = d;
1515
};
1616
Pin::new(&mut b).resume();
17-
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
17+
//~^ ERROR this method takes 1 argument but 0 arguments were supplied
1818
// This type error is required to reproduce the ICE...
1919
}
2020

src/test/ui/generator/issue-102645.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0061]: this function takes 1 argument but 0 arguments were supplied
1+
error[E0061]: this method takes 1 argument but 0 arguments were supplied
22
--> $DIR/issue-102645.rs:16:22
33
|
44
LL | Pin::new(&mut b).resume();

0 commit comments

Comments
 (0)