Skip to content

Commit

Permalink
Rollup merge of #106478 - estebank:tweak-fn-mismatch, r=compiler-errors
Browse files Browse the repository at this point in the history
Tweak wording of fn call with wrong number of args
  • Loading branch information
compiler-errors authored Jan 5, 2023
2 parents 27292f5 + 5393c6b commit e048ee2
Show file tree
Hide file tree
Showing 64 changed files with 143 additions and 146 deletions.
23 changes: 10 additions & 13 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,38 +473,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr: &hir::Expr<'tcx>,
) {
// Next, let's construct the error
let (error_span, full_call_span, ctor_of, is_method) = match &call_expr.kind {
let (error_span, full_call_span, call_name, is_method) = match &call_expr.kind {
hir::ExprKind::Call(
hir::Expr { hir_id, span, kind: hir::ExprKind::Path(qpath), .. },
_,
) => {
if let Res::Def(DefKind::Ctor(of, _), _) =
self.typeck_results.borrow().qpath_res(qpath, *hir_id)
{
(call_span, *span, Some(of), false)
let name = match of {
CtorOf::Struct => "struct",
CtorOf::Variant => "enum variant",
};
(call_span, *span, name, false)
} else {
(call_span, *span, None, false)
(call_span, *span, "function", false)
}
}
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, None, false),
hir::ExprKind::Call(hir::Expr { span, .. }, _) => (call_span, *span, "function", false),
hir::ExprKind::MethodCall(path_segment, _, _, span) => {
let ident_span = path_segment.ident.span;
let ident_span = if let Some(args) = path_segment.args {
ident_span.with_hi(args.span_ext.hi())
} else {
ident_span
};
// methods are never ctors
(*span, ident_span, None, true)
(*span, ident_span, "method", true)
}
k => span_bug!(call_span, "checking argument types on a non-call: `{:?}`", k),
};
let args_span = error_span.trim_start(full_call_span).unwrap_or(error_span);
let call_name = match ctor_of {
Some(CtorOf::Struct) => "struct",
Some(CtorOf::Variant) => "enum variant",
None => "function",
};

// Don't print if it has error types or is just plain `_`
fn has_error_or_infer<'tcx>(tys: impl IntoIterator<Item = Ty<'tcx>>) -> bool {
Expand Down Expand Up @@ -690,8 +688,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err = tcx.sess.struct_span_err_with_code(
full_call_span,
&format!(
"this {} takes {}{} but {} {} supplied",
call_name,
"{call_name} takes {}{} but {} {} supplied",
if c_variadic { "at least " } else { "" },
potentially_plural_count(
formal_and_expected_inputs.len(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
struct Layout;

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

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/argument-suggestions/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn permuted(_x: X, _y: Y, _z: Z) {}

fn main() {
invalid(1.0); //~ ERROR mismatched types
extra(""); //~ ERROR this function takes
missing(); //~ ERROR this function takes
extra(""); //~ ERROR function takes
missing(); //~ ERROR function takes
swapped("", 1); //~ ERROR arguments to this function are incorrect
permuted(Y {}, Z {}, X {}); //~ ERROR arguments to this function are incorrect

let closure = |x| x;
closure(); //~ ERROR this function takes
closure(); //~ ERROR function takes
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/display-is-suggestable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn foo(x: &(dyn Display + Send)) {}

fn main() {
foo();
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
//~^ ERROR function takes 1 argument but 0 arguments were supplied
}
8 changes: 4 additions & 4 deletions src/test/ui/argument-suggestions/exotic-calls.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
fn foo<T: Fn()>(t: T) {
t(1i32);
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
//~^ ERROR function takes 0 arguments but 1 argument was supplied
}

fn bar(t: impl Fn()) {
t(1i32);
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
//~^ ERROR function takes 0 arguments but 1 argument was supplied
}

fn baz() -> impl Fn() {
Expand All @@ -14,13 +14,13 @@ fn baz() -> impl Fn() {

fn baz2() {
baz()(1i32)
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
//~^ ERROR function takes 0 arguments but 1 argument was supplied
}

fn qux() {
let x = || {};
x(1i32);
//~^ ERROR this function takes 0 arguments but 1 argument was supplied
//~^ ERROR function takes 0 arguments but 1 argument was supplied
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/extern-fn-arg-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ extern "Rust" {

fn main() {
dstfn(1);
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
//~^ ERROR function takes 2 arguments but 1 argument was supplied
}
28 changes: 14 additions & 14 deletions src/test/ui/argument-suggestions/extra_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ fn two_arg_same(_a: i32, _b: i32) {}
fn two_arg_diff(_a: i32, _b: &str) {}

fn main() {
empty(""); //~ ERROR this function takes
empty(""); //~ ERROR function takes

one_arg(1, 1); //~ ERROR this function takes
one_arg(1, ""); //~ ERROR this function takes
one_arg(1, "", 1.0); //~ ERROR this function takes
one_arg(1, 1); //~ ERROR function takes
one_arg(1, ""); //~ ERROR function takes
one_arg(1, "", 1.0); //~ ERROR function takes

two_arg_same(1, 1, 1); //~ ERROR this function takes
two_arg_same(1, 1, 1.0); //~ ERROR this function takes
two_arg_same(1, 1, 1); //~ ERROR function takes
two_arg_same(1, 1, 1.0); //~ ERROR function takes

two_arg_diff(1, 1, ""); //~ ERROR this function takes
two_arg_diff(1, "", ""); //~ ERROR this function takes
two_arg_diff(1, 1, "", ""); //~ ERROR this function takes
two_arg_diff(1, "", 1, ""); //~ ERROR this function takes
two_arg_diff(1, 1, ""); //~ ERROR function takes
two_arg_diff(1, "", ""); //~ ERROR function takes
two_arg_diff(1, 1, "", ""); //~ ERROR function takes
two_arg_diff(1, "", 1, ""); //~ ERROR function takes

// Check with weird spacing and newlines
two_arg_same(1, 1, ""); //~ ERROR this function takes
two_arg_diff(1, 1, ""); //~ ERROR this function takes
two_arg_same( //~ ERROR this function takes
two_arg_same(1, 1, ""); //~ ERROR function takes
two_arg_diff(1, 1, ""); //~ ERROR function takes
two_arg_same( //~ ERROR function takes
1,
1,
""
);

two_arg_diff( //~ ERROR this function takes
two_arg_diff( //~ ERROR function takes
1,
1,
""
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-100154.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ fn foo(i: impl std::fmt::Display) {}

fn main() {
foo::<()>(());
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
//~^ ERROR function takes 0 generic arguments but 1 generic argument was supplied
//~| ERROR `()` doesn't implement `std::fmt::Display`
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-100478.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn three_diff(_a: T1, _b: T2, _c: T3) {}
fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {}

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-101097.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn f(
) {}

fn main() {
f(C, A, A, A, B, B, C); //~ ERROR this function takes 6 arguments but 7 arguments were supplied [E0061]
f(C, A, A, A, B, B, C); //~ ERROR function takes 6 arguments but 7 arguments were supplied [E0061]
f(C, C, A, A, B, B); //~ ERROR arguments to this function are incorrect [E0308]
f(A, A, D, D, B, B); //~ arguments to this function are incorrect [E0308]
f(C, C, B, B, A, A); //~ arguments to this function are incorrect [E0308]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-96638.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fn arg<T>() -> T { todo!() }
fn main() {
let x = arg(); // `x` must be inferred
// The reference on `&x` is important to reproduce the ICE
f(&x, ""); //~ ERROR this function takes 3 arguments but 2 arguments were supplied
f(&x, ""); //~ ERROR function takes 3 arguments but 2 arguments were supplied
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-97197.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
g((), ());
//~^ ERROR this function takes 6 arguments but 2 arguments were supplied
//~^ ERROR function takes 6 arguments but 2 arguments were supplied
}

pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-97484.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ fn foo(a: &A, d: D, e: &E, g: G) {}

fn main() {
foo(&&A, B, C, D, E, F, G);
//~^ ERROR this function takes 4 arguments but 7 arguments were supplied
//~^ ERROR function takes 4 arguments but 7 arguments were supplied
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-98894.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
(|_, ()| ())(if true {} else {return;});
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
//~^ ERROR function takes 2 arguments but 1 argument was supplied
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-98897.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
(|_, ()| ())([return, ()]);
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
//~^ ERROR function takes 2 arguments but 1 argument was supplied
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/issue-99482.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
let f = |_: (), f: fn()| f;
let _f = f(main);
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
//~^ ERROR function takes 2 arguments but 1 argument was supplied
}
38 changes: 19 additions & 19 deletions src/test/ui/argument-suggestions/missing_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {}
fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {}

fn main() {
one_arg(); //~ ERROR this function takes
one_arg(); //~ ERROR function takes
// The headers here show the types expected,
// with formatting to emphasize which arguments are missing
/* i32 f32 */
two_same( ); //~ ERROR this function takes
two_same( 1 ); //~ ERROR this function takes
two_diff( ); //~ ERROR this function takes
two_diff( 1 ); //~ ERROR this function takes
two_diff( 1.0 ); //~ ERROR this function takes
two_same( ); //~ ERROR function takes
two_same( 1 ); //~ ERROR function takes
two_diff( ); //~ ERROR function takes
two_diff( 1 ); //~ ERROR function takes
two_diff( 1.0 ); //~ ERROR function takes

/* i32 i32 i32 */
three_same( ); //~ ERROR this function takes
three_same( 1 ); //~ ERROR this function takes
three_same( 1, 1 ); //~ ERROR this function takes
three_same( ); //~ ERROR function takes
three_same( 1 ); //~ ERROR function takes
three_same( 1, 1 ); //~ ERROR function takes

/* i32 f32 &str */
three_diff( 1.0, "" ); //~ ERROR this function takes
three_diff( 1, "" ); //~ ERROR this function takes
three_diff( 1, 1.0 ); //~ ERROR this function takes
three_diff( "" ); //~ ERROR this function takes
three_diff( 1.0 ); //~ ERROR this function takes
three_diff( 1 ); //~ ERROR this function takes
three_diff( 1.0, "" ); //~ ERROR function takes
three_diff( 1, "" ); //~ ERROR function takes
three_diff( 1, 1.0 ); //~ ERROR function takes
three_diff( "" ); //~ ERROR function takes
three_diff( 1.0 ); //~ ERROR function takes
three_diff( 1 ); //~ ERROR function takes

/* i32 f32 f32 &str */
four_repeated( ); //~ ERROR this function takes
four_repeated( 1, "" ); //~ ERROR this function takes
four_repeated( ); //~ ERROR function takes
four_repeated( 1, "" ); //~ ERROR function takes

/* i32 f32 i32 f32 &str */
complex( ); //~ ERROR this function takes
complex( 1, "" ); //~ ERROR this function takes
complex( ); //~ ERROR function takes
complex( 1, "" ); //~ ERROR function takes
}
8 changes: 4 additions & 4 deletions src/test/ui/argument-suggestions/mixed_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ fn three_args(_a: i32, _b: f32, _c: &str) {}

fn main() {
// Extra + Invalid
two_args(1, "", X {}); //~ ERROR this function takes
three_args(1, "", X {}, ""); //~ ERROR this function takes
two_args(1, "", X {}); //~ ERROR function takes
three_args(1, "", X {}, ""); //~ ERROR function takes

// Missing and Invalid
three_args(1, X {}); //~ ERROR this function takes
three_args(1, X {}); //~ ERROR function takes

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

// Swapped and missing
three_args("", 1); //~ ERROR this function takes
three_args("", 1); //~ ERROR function takes
}
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/too-long.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l);
| --- ^ expected `i32`, found `&i32`
| |
| arguments to this function are incorrect
| arguments to this method are incorrect
|
note: associated function defined here
--> $DIR/too-long.rs:4:8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ error[E0308]: mismatched types
LL | fn f() { ModelT.chip_paint(Blue); }
| ---------- ^^^^ expected struct `Black`, found struct `Blue`
| |
| arguments to this function are incorrect
| arguments to this method are incorrect
|
note: associated function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
Expand All @@ -46,7 +46,7 @@ error[E0308]: mismatched types
LL | fn g() { ModelU.chip_paint(Black); }
| ---------- ^^^^^ expected struct `Blue`, found struct `Black`
| |
| arguments to this function are incorrect
| arguments to this method are incorrect
|
note: associated function defined here
--> $DIR/associated-type-projection-from-supertrait.rs:12:8
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/c-variadic/variadic-ffi-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ extern "C" fn bar(f: isize, x: u8) {}

fn main() {
unsafe {
foo(); //~ ERROR this function takes at least 2 arguments but 0 arguments were supplied
foo(1); //~ ERROR this function takes at least 2 arguments but 1 argument was supplied
foo(); //~ ERROR function takes at least 2 arguments but 0 arguments were supplied
foo(1); //~ ERROR function takes at least 2 arguments but 1 argument was supplied

let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~ ERROR mismatched types
let y: extern "C" fn(f: isize, x: u8, ...) = bar; //~ ERROR mismatched types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {

fn main() {
test::<2>();
//~^ ERROR this function takes 2 generic arguments
//~^ ERROR function takes 2 generic arguments
}
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/incorrect-number-of-const-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ fn foo<const X: usize, const Y: usize>() -> usize {

fn main() {
foo::<0>();
//~^ ERROR this function takes 2
//~^ ERROR function takes 2

foo::<0, 0, 0>();
//~^ ERROR this function takes 2
//~^ ERROR function takes 2
}
2 changes: 1 addition & 1 deletion src/test/ui/fn/issue-3044.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let needlesArr: Vec<char> = vec!['a', 'f'];
needlesArr.iter().fold(|x, y| {
//~^ ERROR this function takes 2 arguments but 1 argument was supplied
//~^ ERROR this method takes 2 arguments but 1 argument was supplied
});
}
2 changes: 1 addition & 1 deletion src/test/ui/fn/issue-3044.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0061]: this function takes 2 arguments but 1 argument was supplied
error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> $DIR/issue-3044.rs:3:23
|
LL | needlesArr.iter().fold(|x, y| {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/issue-102645.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
a = d;
};
Pin::new(&mut b).resume();
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
//~^ ERROR this method takes 1 argument but 0 arguments were supplied
// This type error is required to reproduce the ICE...
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generator/issue-102645.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0061]: this function takes 1 argument but 0 arguments were supplied
error[E0061]: this method takes 1 argument but 0 arguments were supplied
--> $DIR/issue-102645.rs:16:22
|
LL | Pin::new(&mut b).resume();
Expand Down
Loading

0 comments on commit e048ee2

Please sign in to comment.