Skip to content

Commit e048ee2

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 27292f5 + 5393c6b commit e048ee2

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

Lines changed: 10 additions & 13 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 14 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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]

0 commit comments

Comments
 (0)