diff options
Diffstat (limited to '')
32 files changed, 1736 insertions, 0 deletions
diff --git a/src/test/ui/argument-suggestions/basic.rs b/src/test/ui/argument-suggestions/basic.rs new file mode 100644 index 000000000..3e96322d6 --- /dev/null +++ b/src/test/ui/argument-suggestions/basic.rs @@ -0,0 +1,28 @@ +// Some basic "obvious" cases for the heuristic error messages added for #65853 +// One for each of the detected cases + +enum E { X, Y } +enum F { X2, Y2 } +struct G {} +struct H {} +struct X {} +struct Y {} +struct Z {} + + +fn invalid(_i: u32) {} +fn extra() {} +fn missing(_i: u32) {} +fn swapped(_i: u32, _s: &str) {} +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 + 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 +} diff --git a/src/test/ui/argument-suggestions/basic.stderr b/src/test/ui/argument-suggestions/basic.stderr new file mode 100644 index 000000000..c495ad6b8 --- /dev/null +++ b/src/test/ui/argument-suggestions/basic.stderr @@ -0,0 +1,103 @@ +error[E0308]: mismatched types + --> $DIR/basic.rs:20:13 + | +LL | invalid(1.0); + | ------- ^^^ expected `u32`, found floating-point number + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/basic.rs:13:4 + | +LL | fn invalid(_i: u32) {} + | ^^^^^^^ ------- + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/basic.rs:21:5 + | +LL | extra(""); + | ^^^^^ -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/basic.rs:14:4 + | +LL | fn extra() {} + | ^^^^^ +help: remove the extra argument + | +LL | extra(); + | ~~~~~~~ + +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/basic.rs:22:5 + | +LL | missing(); + | ^^^^^^^-- an argument of type `u32` is missing + | +note: function defined here + --> $DIR/basic.rs:15:4 + | +LL | fn missing(_i: u32) {} + | ^^^^^^^ ------- +help: provide the argument + | +LL | missing(/* u32 */); + | ~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/basic.rs:23:5 + | +LL | swapped("", 1); + | ^^^^^^^ -- - expected `&str`, found `{integer}` + | | + | expected `u32`, found `&'static str` + | +note: function defined here + --> $DIR/basic.rs:16:4 + | +LL | fn swapped(_i: u32, _s: &str) {} + | ^^^^^^^ ------- -------- +help: swap these arguments + | +LL | swapped(1, ""); + | ~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/basic.rs:24:5 + | +LL | permuted(Y {}, Z {}, X {}); + | ^^^^^^^^ ---- ---- ---- expected `Z`, found `X` + | | | + | | expected `Y`, found `Z` + | expected `X`, found `Y` + | +note: function defined here + --> $DIR/basic.rs:17:4 + | +LL | fn permuted(_x: X, _y: Y, _z: Z) {} + | ^^^^^^^^ ----- ----- ----- +help: reorder these arguments + | +LL | permuted(X {}, Y {}, Z {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0057]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/basic.rs:27:5 + | +LL | closure(); + | ^^^^^^^-- an argument is missing + | +note: closure defined here + --> $DIR/basic.rs:26:19 + | +LL | let closure = |x| x; + | ^^^ +help: provide the argument + | +LL | closure(/* value */); + | ~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0057, E0061, E0308. +For more information about an error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/complex.rs b/src/test/ui/argument-suggestions/complex.rs new file mode 100644 index 000000000..384cdca7e --- /dev/null +++ b/src/test/ui/argument-suggestions/complex.rs @@ -0,0 +1,16 @@ +// A complex case with mixed suggestions from #65853 + +enum E { X, Y } +enum F { X2, Y2 } +struct G {} +struct H {} +struct X {} +struct Y {} +struct Z {} + +fn complex(_i: u32, _s: &str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {} + +fn main() { + complex(1.0, H {}, &"", G{}, F::X2, Z {}, X {}, Y {}); + //~^ ERROR arguments to this function are incorrect +} diff --git a/src/test/ui/argument-suggestions/complex.stderr b/src/test/ui/argument-suggestions/complex.stderr new file mode 100644 index 000000000..fa030a8f4 --- /dev/null +++ b/src/test/ui/argument-suggestions/complex.stderr @@ -0,0 +1,19 @@ +error[E0308]: arguments to this function are incorrect + --> $DIR/complex.rs:14:3 + | +LL | complex(1.0, H {}, &"", G{}, F::X2, Z {}, X {}, Y {}); + | ^^^^^^^ --- expected `u32`, found floating-point number + | +note: function defined here + --> $DIR/complex.rs:11:4 + | +LL | fn complex(_i: u32, _s: &str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {} + | ^^^^^^^ ------- -------- ----- ----- ----- ----- ----- ------ +help: did you mean + | +LL | complex(/* u32 */, &"", /* E */, F::X2, G{}, X {}, Y {}, Z {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/argument-suggestions/exotic-calls.rs b/src/test/ui/argument-suggestions/exotic-calls.rs new file mode 100644 index 000000000..a18e96766 --- /dev/null +++ b/src/test/ui/argument-suggestions/exotic-calls.rs @@ -0,0 +1,26 @@ +fn foo<T: Fn()>(t: T) { + t(1i32); + //~^ ERROR this 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 +} + +fn baz() -> impl Fn() { + || {} +} + +fn baz2() { + baz()(1i32) + //~^ ERROR this 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 +} + +fn main() {} diff --git a/src/test/ui/argument-suggestions/exotic-calls.stderr b/src/test/ui/argument-suggestions/exotic-calls.stderr new file mode 100644 index 000000000..ca93ecc4e --- /dev/null +++ b/src/test/ui/argument-suggestions/exotic-calls.stderr @@ -0,0 +1,67 @@ +error[E0057]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/exotic-calls.rs:2:5 + | +LL | t(1i32); + | ^ ---- argument of type `i32` unexpected + | +note: callable defined here + --> $DIR/exotic-calls.rs:1:11 + | +LL | fn foo<T: Fn()>(t: T) { + | ^^^^ +help: remove the extra argument + | +LL | t(); + | ~~~ + +error[E0057]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/exotic-calls.rs:7:5 + | +LL | t(1i32); + | ^ ---- argument of type `i32` unexpected + | +note: type parameter defined here + --> $DIR/exotic-calls.rs:6:11 + | +LL | fn bar(t: impl Fn()) { + | ^^^^^^^^^ +help: remove the extra argument + | +LL | t(); + | ~~~ + +error[E0057]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/exotic-calls.rs:16:5 + | +LL | baz()(1i32) + | ^^^^^ ---- argument of type `i32` unexpected + | +note: opaque type defined here + --> $DIR/exotic-calls.rs:11:13 + | +LL | fn baz() -> impl Fn() { + | ^^^^^^^^^ +help: remove the extra argument + | +LL | baz()() + | + +error[E0057]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/exotic-calls.rs:22:5 + | +LL | x(1i32); + | ^ ---- argument of type `i32` unexpected + | +note: closure defined here + --> $DIR/exotic-calls.rs:21:13 + | +LL | let x = || {}; + | ^^ +help: remove the extra argument + | +LL | x(); + | ~~~ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/extra_arguments.rs b/src/test/ui/argument-suggestions/extra_arguments.rs new file mode 100644 index 000000000..3706ac4e8 --- /dev/null +++ b/src/test/ui/argument-suggestions/extra_arguments.rs @@ -0,0 +1,35 @@ +fn empty() {} +fn one_arg(_a: i32) {} +fn two_arg_same(_a: i32, _b: i32) {} +fn two_arg_diff(_a: i32, _b: &str) {} + +fn main() { + empty(""); //~ ERROR this 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 + + two_arg_same(1, 1, 1); //~ ERROR this function takes + two_arg_same(1, 1, 1.0); //~ ERROR this 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 + + // 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 + 1, + 1, + "" + ); + + two_arg_diff( //~ ERROR this function takes + 1, + 1, + "" + ); +} diff --git a/src/test/ui/argument-suggestions/extra_arguments.stderr b/src/test/ui/argument-suggestions/extra_arguments.stderr new file mode 100644 index 000000000..32b1e1573 --- /dev/null +++ b/src/test/ui/argument-suggestions/extra_arguments.stderr @@ -0,0 +1,239 @@ +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/extra_arguments.rs:7:3 + | +LL | empty(""); + | ^^^^^ -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:1:4 + | +LL | fn empty() {} + | ^^^^^ +help: remove the extra argument + | +LL | empty(); + | ~~~~~~~ + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/extra_arguments.rs:9:3 + | +LL | one_arg(1, 1); + | ^^^^^^^ - argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:2:4 + | +LL | fn one_arg(_a: i32) {} + | ^^^^^^^ ------- +help: remove the extra argument + | +LL | one_arg(1); + | ~~~~~~~~~~ + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/extra_arguments.rs:10:3 + | +LL | one_arg(1, ""); + | ^^^^^^^ -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:2:4 + | +LL | fn one_arg(_a: i32) {} + | ^^^^^^^ ------- +help: remove the extra argument + | +LL | one_arg(1); + | ~~~~~~~~~~ + +error[E0061]: this function takes 1 argument but 3 arguments were supplied + --> $DIR/extra_arguments.rs:11:3 + | +LL | one_arg(1, "", 1.0); + | ^^^^^^^ -- --- argument of type `{float}` unexpected + | | + | argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:2:4 + | +LL | fn one_arg(_a: i32) {} + | ^^^^^^^ ------- +help: remove the extra arguments + | +LL | one_arg(1); + | ~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:13:3 + | +LL | two_arg_same(1, 1, 1); + | ^^^^^^^^^^^^ - argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:3:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL | two_arg_same(1, 1); + | ~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:14:3 + | +LL | two_arg_same(1, 1, 1.0); + | ^^^^^^^^^^^^ --- argument of type `{float}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:3:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL | two_arg_same(1, 1); + | ~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:16:3 + | +LL | two_arg_diff(1, 1, ""); + | ^^^^^^^^^^^^ - argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:17:3 + | +LL | two_arg_diff(1, "", ""); + | ^^^^^^^^^^^^ -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 4 arguments were supplied + --> $DIR/extra_arguments.rs:18:3 + | +LL | two_arg_diff(1, 1, "", ""); + | ^^^^^^^^^^^^ - -- argument of type `&'static str` unexpected + | | + | argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra arguments + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 4 arguments were supplied + --> $DIR/extra_arguments.rs:19:3 + | +LL | two_arg_diff(1, "", 1, ""); + | ^^^^^^^^^^^^ - -- argument of type `&'static str` unexpected + | | + | argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra arguments + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:22:3 + | +LL | two_arg_same(1, 1, ""); + | ^^^^^^^^^^^^ -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:3:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL | two_arg_same(1, 1); + | ~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:23:3 + | +LL | two_arg_diff(1, 1, ""); + | ^^^^^^^^^^^^ - argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:24:3 + | +LL | two_arg_same( + | ^^^^^^^^^^^^ +... +LL | "" + | -- argument of type `&'static str` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:3:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL | two_arg_same(1, 1); + | ~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/extra_arguments.rs:30:3 + | +LL | two_arg_diff( + | ^^^^^^^^^^^^ +LL | 1, +LL | 1, + | - argument of type `{integer}` unexpected + | +note: function defined here + --> $DIR/extra_arguments.rs:4:4 + | +LL | fn two_arg_diff(_a: i32, _b: &str) {} + | ^^^^^^^^^^^^ ------- -------- +help: remove the extra argument + | +LL | two_arg_diff(1, ""); + | ~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 14 previous errors + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/invalid_arguments.rs b/src/test/ui/argument-suggestions/invalid_arguments.rs new file mode 100644 index 000000000..53fbdd4b5 --- /dev/null +++ b/src/test/ui/argument-suggestions/invalid_arguments.rs @@ -0,0 +1,43 @@ +// More nuanced test cases for invalid arguments #65853 + +struct X {} + +fn one_arg(_a: i32) {} +fn two_arg_same(_a: i32, _b: i32) {} +fn two_arg_diff(_a: i32, _b: f32) {} +fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} +fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + +fn main() { + // Providing an incorrect argument for a single parameter function + one_arg(1.0); //~ ERROR mismatched types + + // Providing one or two invalid arguments to a two parameter function + two_arg_same(1, ""); //~ ERROR mismatched types + two_arg_same("", 1); //~ ERROR mismatched types + two_arg_same("", ""); //~ ERROR arguments to this function are incorrect + two_arg_diff(1, ""); //~ ERROR mismatched types + two_arg_diff("", 1.0); //~ ERROR mismatched types + two_arg_diff("", ""); //~ ERROR arguments to this function are incorrect + + // Providing invalid arguments to a three parameter function + three_arg_diff(X{}, 1.0, ""); //~ ERROR mismatched types + three_arg_diff(1, X {}, ""); //~ ERROR mismatched types + three_arg_diff(1, 1.0, X {}); //~ ERROR mismatched types + + three_arg_diff(X {}, X {}, ""); //~ ERROR arguments to this function are incorrect + three_arg_diff(X {}, 1.0, X {}); //~ ERROR arguments to this function are incorrect + three_arg_diff(1, X {}, X {}); //~ ERROR arguments to this function are incorrect + + three_arg_diff(X {}, X {}, X {}); //~ ERROR arguments to this function are incorrect + + three_arg_repeat(X {}, 1, ""); //~ ERROR mismatched types + three_arg_repeat(1, X {}, ""); //~ ERROR mismatched types + three_arg_repeat(1, 1, X {}); //~ ERROR mismatched types + + three_arg_repeat(X {}, X {}, ""); //~ ERROR arguments to this function are incorrect + three_arg_repeat(X {}, 1, X {}); //~ ERROR arguments to this function are incorrect + three_arg_repeat(1, X {}, X{}); //~ ERROR arguments to this function are incorrect + + three_arg_repeat(X {}, X {}, X {}); //~ ERROR arguments to this function are incorrect +} diff --git a/src/test/ui/argument-suggestions/invalid_arguments.stderr b/src/test/ui/argument-suggestions/invalid_arguments.stderr new file mode 100644 index 000000000..33f27d48f --- /dev/null +++ b/src/test/ui/argument-suggestions/invalid_arguments.stderr @@ -0,0 +1,299 @@ +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:13:11 + | +LL | one_arg(1.0); + | ------- ^^^ expected `i32`, found floating-point number + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:5:4 + | +LL | fn one_arg(_a: i32) {} + | ^^^^^^^ ------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:16:19 + | +LL | two_arg_same(1, ""); + | ------------ ^^ expected `i32`, found `&str` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:6:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:17:16 + | +LL | two_arg_same("", 1); + | ------------ ^^ expected `i32`, found `&str` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:6:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:18:3 + | +LL | two_arg_same("", ""); + | ^^^^^^^^^^^^ -- -- expected `i32`, found `&str` + | | + | expected `i32`, found `&str` + | +note: function defined here + --> $DIR/invalid_arguments.rs:6:4 + | +LL | fn two_arg_same(_a: i32, _b: i32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:19:19 + | +LL | two_arg_diff(1, ""); + | ------------ ^^ expected `f32`, found `&str` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:7:4 + | +LL | fn two_arg_diff(_a: i32, _b: f32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:20:16 + | +LL | two_arg_diff("", 1.0); + | ------------ ^^ expected `i32`, found `&str` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:7:4 + | +LL | fn two_arg_diff(_a: i32, _b: f32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:21:3 + | +LL | two_arg_diff("", ""); + | ^^^^^^^^^^^^ -- -- expected `f32`, found `&str` + | | + | expected `i32`, found `&str` + | +note: function defined here + --> $DIR/invalid_arguments.rs:7:4 + | +LL | fn two_arg_diff(_a: i32, _b: f32) {} + | ^^^^^^^^^^^^ ------- ------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:24:18 + | +LL | three_arg_diff(X{}, 1.0, ""); + | -------------- ^^^ expected `i32`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:25:21 + | +LL | three_arg_diff(1, X {}, ""); + | -------------- ^^^^ expected `f32`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:26:26 + | +LL | three_arg_diff(1, 1.0, X {}); + | -------------- ^^^^ expected `&str`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:28:3 + | +LL | three_arg_diff(X {}, X {}, ""); + | ^^^^^^^^^^^^^^ ---- ---- expected `f32`, found struct `X` + | | + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:29:3 + | +LL | three_arg_diff(X {}, 1.0, X {}); + | ^^^^^^^^^^^^^^ ---- ---- expected `&str`, found struct `X` + | | + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:30:3 + | +LL | three_arg_diff(1, X {}, X {}); + | ^^^^^^^^^^^^^^ ---- ---- expected `&str`, found struct `X` + | | + | expected `f32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:32:3 + | +LL | three_arg_diff(X {}, X {}, X {}); + | ^^^^^^^^^^^^^^ ---- ---- ---- expected `&str`, found struct `X` + | | | + | | expected `f32`, found struct `X` + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:8:4 + | +LL | fn three_arg_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:34:20 + | +LL | three_arg_repeat(X {}, 1, ""); + | ---------------- ^^^^ expected `i32`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:35:23 + | +LL | three_arg_repeat(1, X {}, ""); + | ---------------- ^^^^ expected `i32`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: mismatched types + --> $DIR/invalid_arguments.rs:36:26 + | +LL | three_arg_repeat(1, 1, X {}); + | ---------------- ^^^^ expected `&str`, found struct `X` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:38:3 + | +LL | three_arg_repeat(X {}, X {}, ""); + | ^^^^^^^^^^^^^^^^ ---- ---- expected `i32`, found struct `X` + | | + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:39:3 + | +LL | three_arg_repeat(X {}, 1, X {}); + | ^^^^^^^^^^^^^^^^ ---- ---- expected `&str`, found struct `X` + | | + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:40:3 + | +LL | three_arg_repeat(1, X {}, X{}); + | ^^^^^^^^^^^^^^^^ ---- --- expected `&str`, found struct `X` + | | + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error[E0308]: arguments to this function are incorrect + --> $DIR/invalid_arguments.rs:42:3 + | +LL | three_arg_repeat(X {}, X {}, X {}); + | ^^^^^^^^^^^^^^^^ ---- ---- ---- expected `&str`, found struct `X` + | | | + | | expected `i32`, found struct `X` + | expected `i32`, found struct `X` + | +note: function defined here + --> $DIR/invalid_arguments.rs:9:4 + | +LL | fn three_arg_repeat(_a: i32, _b: i32, _c: &str) {} + | ^^^^^^^^^^^^^^^^ ------- ------- -------- + +error: aborting due to 21 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/argument-suggestions/issue-100154.rs b/src/test/ui/argument-suggestions/issue-100154.rs new file mode 100644 index 000000000..4446b4bc2 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-100154.rs @@ -0,0 +1,7 @@ +fn foo(i: impl std::fmt::Display) {} + +fn main() { + foo::<()>(()); + //~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied + //~| ERROR `()` doesn't implement `std::fmt::Display` +} diff --git a/src/test/ui/argument-suggestions/issue-100154.stderr b/src/test/ui/argument-suggestions/issue-100154.stderr new file mode 100644 index 000000000..1499229c3 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-100154.stderr @@ -0,0 +1,35 @@ +error[E0107]: this function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/issue-100154.rs:4:5 + | +LL | foo::<()>(()); + | ^^^------ help: remove these generics + | | + | expected 0 generic arguments + | +note: function defined here, with 0 generic parameters + --> $DIR/issue-100154.rs:1:4 + | +LL | fn foo(i: impl std::fmt::Display) {} + | ^^^ + = note: `impl Trait` cannot be explicitly specified as a generic argument + +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/issue-100154.rs:4:15 + | +LL | foo::<()>(()); + | --------- ^^ `()` cannot be formatted with the default formatter + | | + | required by a bound introduced by this call + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `foo` + --> $DIR/issue-100154.rs:1:16 + | +LL | fn foo(i: impl std::fmt::Display) {} + | ^^^^^^^^^^^^^^^^^ required by this bound in `foo` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0277. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/argument-suggestions/issue-96638.rs b/src/test/ui/argument-suggestions/issue-96638.rs new file mode 100644 index 000000000..9c6e81ab8 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-96638.rs @@ -0,0 +1,9 @@ +fn f(_: usize, _: &usize, _: usize) {} + +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 +} diff --git a/src/test/ui/argument-suggestions/issue-96638.stderr b/src/test/ui/argument-suggestions/issue-96638.stderr new file mode 100644 index 000000000..8af31b8b7 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-96638.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/issue-96638.rs:8:5 + | +LL | f(&x, ""); + | ^ -- an argument of type `usize` is missing + | +note: function defined here + --> $DIR/issue-96638.rs:1:4 + | +LL | fn f(_: usize, _: &usize, _: usize) {} + | ^ -------- --------- -------- +help: provide the argument + | +LL | f(/* usize */, &x, /* usize */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/issue-97197.rs b/src/test/ui/argument-suggestions/issue-97197.rs new file mode 100644 index 000000000..6f9f4293e --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-97197.rs @@ -0,0 +1,6 @@ +fn main() { + g((), ()); + //~^ ERROR this function takes 6 arguments but 2 arguments were supplied +} + +pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {} diff --git a/src/test/ui/argument-suggestions/issue-97197.stderr b/src/test/ui/argument-suggestions/issue-97197.stderr new file mode 100644 index 000000000..ac54adc5e --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-97197.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 6 arguments but 2 arguments were supplied + --> $DIR/issue-97197.rs:2:5 + | +LL | g((), ()); + | ^-------- multiple arguments are missing + | +note: function defined here + --> $DIR/issue-97197.rs:6:8 + | +LL | pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {} + | ^ ------ -------- -------- -------- -------- ------ +help: provide the arguments + | +LL | g((), /* bool */, /* bool */, /* bool */, /* bool */, ()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/issue-97484.rs b/src/test/ui/argument-suggestions/issue-97484.rs new file mode 100644 index 000000000..bb383ab1f --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-97484.rs @@ -0,0 +1,14 @@ +struct A; +struct B; +struct C; +struct D; +struct E; +struct F; +struct G; + +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 +} diff --git a/src/test/ui/argument-suggestions/issue-97484.stderr b/src/test/ui/argument-suggestions/issue-97484.stderr new file mode 100644 index 000000000..9589e919c --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-97484.stderr @@ -0,0 +1,26 @@ +error[E0061]: this function takes 4 arguments but 7 arguments were supplied + --> $DIR/issue-97484.rs:12:5 + | +LL | foo(&&A, B, C, D, E, F, G); + | ^^^ - - - argument of type `F` unexpected + | | | + | | argument of type `C` unexpected + | argument of type `B` unexpected + | +note: function defined here + --> $DIR/issue-97484.rs:9:4 + | +LL | fn foo(a: &A, d: D, e: &E, g: G) {} + | ^^^ ----- ---- ----- ---- +help: consider borrowing here + | +LL | foo(&&A, B, C, D, &E, F, G); + | ~~ +help: remove the extra arguments + | +LL | foo(&&A, D, /* &E */, G); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/issue-98894.rs b/src/test/ui/argument-suggestions/issue-98894.rs new file mode 100644 index 000000000..c2618a967 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98894.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())(if true {} else {return;}); + //~^ ERROR this function takes 2 arguments but 1 argument was supplied +} diff --git a/src/test/ui/argument-suggestions/issue-98894.stderr b/src/test/ui/argument-suggestions/issue-98894.stderr new file mode 100644 index 000000000..0c8b94901 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98894.stderr @@ -0,0 +1,19 @@ +error[E0057]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/issue-98894.rs:2:5 + | +LL | (|_, ()| ())(if true {} else {return;}); + | ^^^^^^^^^^^^--------------------------- an argument of type `()` is missing + | +note: closure defined here + --> $DIR/issue-98894.rs:2:6 + | +LL | (|_, ()| ())(if true {} else {return;}); + | ^^^^^^^ +help: provide the argument + | +LL | (|_, ()| ())(if true {} else {return;}, ()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/issue-98897.rs b/src/test/ui/argument-suggestions/issue-98897.rs new file mode 100644 index 000000000..c55f495d6 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98897.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())([return, ()]); + //~^ ERROR this function takes 2 arguments but 1 argument was supplied +} diff --git a/src/test/ui/argument-suggestions/issue-98897.stderr b/src/test/ui/argument-suggestions/issue-98897.stderr new file mode 100644 index 000000000..8f0d98d09 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-98897.stderr @@ -0,0 +1,19 @@ +error[E0057]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/issue-98897.rs:2:5 + | +LL | (|_, ()| ())([return, ()]); + | ^^^^^^^^^^^^-------------- an argument of type `()` is missing + | +note: closure defined here + --> $DIR/issue-98897.rs:2:6 + | +LL | (|_, ()| ())([return, ()]); + | ^^^^^^^ +help: provide the argument + | +LL | (|_, ()| ())([return, ()], ()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/issue-99482.rs b/src/test/ui/argument-suggestions/issue-99482.rs new file mode 100644 index 000000000..731b86306 --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-99482.rs @@ -0,0 +1,5 @@ +fn main() { + let f = |_: (), f: fn()| f; + let _f = f(main); + //~^ ERROR this function takes 2 arguments but 1 argument was supplied +} diff --git a/src/test/ui/argument-suggestions/issue-99482.stderr b/src/test/ui/argument-suggestions/issue-99482.stderr new file mode 100644 index 000000000..bc005e82a --- /dev/null +++ b/src/test/ui/argument-suggestions/issue-99482.stderr @@ -0,0 +1,19 @@ +error[E0057]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/issue-99482.rs:3:14 + | +LL | let _f = f(main); + | ^ ---- an argument of type `()` is missing + | +note: closure defined here + --> $DIR/issue-99482.rs:2:13 + | +LL | let f = |_: (), f: fn()| f; + | ^^^^^^^^^^^^^^^^ +help: provide the argument + | +LL | let _f = f((), main); + | ~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0057`. diff --git a/src/test/ui/argument-suggestions/missing_arguments.rs b/src/test/ui/argument-suggestions/missing_arguments.rs new file mode 100644 index 000000000..ae0dabf27 --- /dev/null +++ b/src/test/ui/argument-suggestions/missing_arguments.rs @@ -0,0 +1,40 @@ +fn one_arg(_a: i32) {} +fn two_same(_a: i32, _b: i32) {} +fn two_diff(_a: i32, _b: f32) {} +fn three_same(_a: i32, _b: i32, _c: i32) {} +fn three_diff(_a: i32, _b: f32, _c: &str) {} +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 + // 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 + + /* i32 i32 i32 */ + three_same( ); //~ ERROR this function takes + three_same( 1 ); //~ ERROR this function takes + three_same( 1, 1 ); //~ ERROR this 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 + + /* i32 f32 f32 &str */ + four_repeated( ); //~ ERROR this function takes + four_repeated( 1, "" ); //~ ERROR this function takes + + /* i32 f32 i32 f32 &str */ + complex( ); //~ ERROR this function takes + complex( 1, "" ); //~ ERROR this function takes +} diff --git a/src/test/ui/argument-suggestions/missing_arguments.stderr b/src/test/ui/argument-suggestions/missing_arguments.stderr new file mode 100644 index 000000000..2509d22d7 --- /dev/null +++ b/src/test/ui/argument-suggestions/missing_arguments.stderr @@ -0,0 +1,310 @@ +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/missing_arguments.rs:10:3 + | +LL | one_arg(); + | ^^^^^^^-- an argument of type `i32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:1:4 + | +LL | fn one_arg(_a: i32) {} + | ^^^^^^^ ------- +help: provide the argument + | +LL | one_arg(/* i32 */); + | ~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 0 arguments were supplied + --> $DIR/missing_arguments.rs:14:3 + | +LL | two_same( ); + | ^^^^^^^^----------------- two arguments of type `i32` and `i32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:2:4 + | +LL | fn two_same(_a: i32, _b: i32) {} + | ^^^^^^^^ ------- ------- +help: provide the arguments + | +LL | two_same(/* i32 */, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:15:3 + | +LL | two_same( 1 ); + | ^^^^^^^^----------------- an argument of type `i32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:2:4 + | +LL | fn two_same(_a: i32, _b: i32) {} + | ^^^^^^^^ ------- ------- +help: provide the argument + | +LL | two_same(1, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 0 arguments were supplied + --> $DIR/missing_arguments.rs:16:3 + | +LL | two_diff( ); + | ^^^^^^^^----------------- two arguments of type `i32` and `f32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:3:4 + | +LL | fn two_diff(_a: i32, _b: f32) {} + | ^^^^^^^^ ------- ------- +help: provide the arguments + | +LL | two_diff(/* i32 */, /* f32 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:17:3 + | +LL | two_diff( 1 ); + | ^^^^^^^^----------------- an argument of type `f32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:3:4 + | +LL | fn two_diff(_a: i32, _b: f32) {} + | ^^^^^^^^ ------- ------- +help: provide the argument + | +LL | two_diff(1, /* f32 */); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:18:3 + | +LL | two_diff( 1.0 ); + | ^^^^^^^^ --- an argument of type `i32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:3:4 + | +LL | fn two_diff(_a: i32, _b: f32) {} + | ^^^^^^^^ ------- ------- +help: provide the argument + | +LL | two_diff(/* i32 */, 1.0); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 0 arguments were supplied + --> $DIR/missing_arguments.rs:21:3 + | +LL | three_same( ); + | ^^^^^^^^^^------------------------- three arguments of type `i32`, `i32`, and `i32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:4:4 + | +LL | fn three_same(_a: i32, _b: i32, _c: i32) {} + | ^^^^^^^^^^ ------- ------- ------- +help: provide the arguments + | +LL | three_same(/* i32 */, /* i32 */, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:22:3 + | +LL | three_same( 1 ); + | ^^^^^^^^^^------------------------- two arguments of type `i32` and `i32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:4:4 + | +LL | fn three_same(_a: i32, _b: i32, _c: i32) {} + | ^^^^^^^^^^ ------- ------- ------- +help: provide the arguments + | +LL | three_same(1, /* i32 */, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:23:3 + | +LL | three_same( 1, 1 ); + | ^^^^^^^^^^------------------------- an argument of type `i32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:4:4 + | +LL | fn three_same(_a: i32, _b: i32, _c: i32) {} + | ^^^^^^^^^^ ------- ------- ------- +help: provide the argument + | +LL | three_same(1, 1, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:26:3 + | +LL | three_diff( 1.0, "" ); + | ^^^^^^^^^^ --- an argument of type `i32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the argument + | +LL | three_diff(/* i32 */, 1.0, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:27:3 + | +LL | three_diff( 1, "" ); + | ^^^^^^^^^^ -- an argument of type `f32` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the argument + | +LL | three_diff(1, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:28:3 + | +LL | three_diff( 1, 1.0 ); + | ^^^^^^^^^^------------------------- an argument of type `&str` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the argument + | +LL | three_diff(1, 1.0, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:29:3 + | +LL | three_diff( "" ); + | ^^^^^^^^^^------------------------- two arguments of type `i32` and `f32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the arguments + | +LL | three_diff(/* i32 */, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:30:3 + | +LL | three_diff( 1.0 ); + | ^^^^^^^^^^------------------------- + | | | + | | an argument of type `i32` is missing + | an argument of type `&str` is missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the arguments + | +LL | three_diff(/* i32 */, 1.0, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 1 argument was supplied + --> $DIR/missing_arguments.rs:31:3 + | +LL | three_diff( 1 ); + | ^^^^^^^^^^------------------------- two arguments of type `f32` and `&str` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:5:4 + | +LL | fn three_diff(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the arguments + | +LL | three_diff(1, /* f32 */, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 4 arguments but 0 arguments were supplied + --> $DIR/missing_arguments.rs:34:3 + | +LL | four_repeated( ); + | ^^^^^^^^^^^^^--------------------------------- multiple arguments are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:6:4 + | +LL | fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {} + | ^^^^^^^^^^^^^ ------- ------- ------- -------- +help: provide the arguments + | +LL | four_repeated(/* i32 */, /* f32 */, /* f32 */, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 4 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:35:3 + | +LL | four_repeated( 1, "" ); + | ^^^^^^^^^^^^^--------------------------------- two arguments of type `f32` and `f32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:6:4 + | +LL | fn four_repeated(_a: i32, _b: f32, _c: f32, _d: &str) {} + | ^^^^^^^^^^^^^ ------- ------- ------- -------- +help: provide the arguments + | +LL | four_repeated(1, /* f32 */, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 5 arguments but 0 arguments were supplied + --> $DIR/missing_arguments.rs:38:3 + | +LL | complex( ); + | ^^^^^^^--------------------------------- multiple arguments are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:7:4 + | +LL | fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {} + | ^^^^^^^ ------- ------- ------- ------- -------- +help: provide the arguments + | +LL | complex(/* i32 */, /* f32 */, /* i32 */, /* f32 */, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 5 arguments but 2 arguments were supplied + --> $DIR/missing_arguments.rs:39:3 + | +LL | complex( 1, "" ); + | ^^^^^^^--------------------------------- three arguments of type `f32`, `i32`, and `f32` are missing + | +note: function defined here + --> $DIR/missing_arguments.rs:7:4 + | +LL | fn complex(_a: i32, _b: f32, _c: i32, _d: f32, _e: &str) {} + | ^^^^^^^ ------- ------- ------- ------- -------- +help: provide the arguments + | +LL | complex(1, /* f32 */, /* i32 */, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 19 previous errors + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/mixed_cases.rs b/src/test/ui/argument-suggestions/mixed_cases.rs new file mode 100644 index 000000000..73678482b --- /dev/null +++ b/src/test/ui/argument-suggestions/mixed_cases.rs @@ -0,0 +1,24 @@ +// Cases where multiple argument suggestions are mixed + +struct X {} + +fn two_args(_a: i32, _b: f32) {} +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 + + // Missing and Invalid + three_args(1, X {}); //~ ERROR this function takes + + // Missing and Extra + three_args(1, "", X {}); //~ ERROR arguments to this function are incorrect + + // Swapped and Invalid + three_args("", X {}, 1); //~ ERROR arguments to this function are incorrect + + // Swapped and missing + three_args("", 1); //~ ERROR this function takes +} diff --git a/src/test/ui/argument-suggestions/mixed_cases.stderr b/src/test/ui/argument-suggestions/mixed_cases.stderr new file mode 100644 index 000000000..a52a30d78 --- /dev/null +++ b/src/test/ui/argument-suggestions/mixed_cases.stderr @@ -0,0 +1,117 @@ +error[E0061]: this function takes 2 arguments but 3 arguments were supplied + --> $DIR/mixed_cases.rs:10:3 + | +LL | two_args(1, "", X {}); + | ^^^^^^^^ -- ---- argument of type `X` unexpected + | | + | expected `f32`, found `&str` + | +note: function defined here + --> $DIR/mixed_cases.rs:5:4 + | +LL | fn two_args(_a: i32, _b: f32) {} + | ^^^^^^^^ ------- ------- +help: remove the extra argument + | +LL | two_args(1, /* f32 */); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 4 arguments were supplied + --> $DIR/mixed_cases.rs:11:3 + | +LL | three_args(1, "", X {}, ""); + | ^^^^^^^^^^ -- ---- -- argument of type `&'static str` unexpected + | | | + | | argument of type `X` unexpected + | an argument of type `f32` is missing + | +note: function defined here + --> $DIR/mixed_cases.rs:6:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: did you mean + | +LL | three_args(1, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/mixed_cases.rs:14:3 + | +LL | three_args(1, X {}); + | ^^^^^^^^^^--------- + | | | + | | expected `f32`, found struct `X` + | an argument of type `&str` is missing + | +note: function defined here + --> $DIR/mixed_cases.rs:6:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: provide the argument + | +LL | three_args(1, /* f32 */, /* &str */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/mixed_cases.rs:17:3 + | +LL | three_args(1, "", X {}); + | ^^^^^^^^^^ -- ---- argument of type `X` unexpected + | | + | an argument of type `f32` is missing + | +note: function defined here + --> $DIR/mixed_cases.rs:6:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: did you mean + | +LL | three_args(1, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/mixed_cases.rs:20:3 + | +LL | three_args("", X {}, 1); + | ^^^^^^^^^^ -- ---- - expected `&str`, found `{integer}` + | | | + | | expected `f32`, found struct `X` + | expected `i32`, found `&'static str` + | +note: function defined here + --> $DIR/mixed_cases.rs:6:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: swap these arguments + | +LL | three_args(1, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/mixed_cases.rs:23:3 + | +LL | three_args("", 1); + | ^^^^^^^^^^ -- - + | | | + | | an argument of type `f32` is missing + | | expected `&str`, found `{integer}` + | expected `i32`, found `&'static str` + | +note: function defined here + --> $DIR/mixed_cases.rs:6:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: did you mean + | +LL | three_args(1, /* f32 */, ""); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0061, E0308. +For more information about an error, try `rustc --explain E0061`. diff --git a/src/test/ui/argument-suggestions/permuted_arguments.rs b/src/test/ui/argument-suggestions/permuted_arguments.rs new file mode 100644 index 000000000..f512fde65 --- /dev/null +++ b/src/test/ui/argument-suggestions/permuted_arguments.rs @@ -0,0 +1,13 @@ +// More complicated permutations +struct X {} +struct Y {} + +fn three_args(_a: i32, _b: f32, _c: &str) {} +fn many_args(_a: i32, _b: f32, _c: &str, _d: X, _e: Y) {} + +fn main() { + // b, c, a + three_args(1.0, "", 1); //~ ERROR arguments to this function are incorrect + // d, e, b, a, c + many_args(X {}, Y {}, 1, 1.0, ""); //~ ERROR arguments to this function are incorrect +} diff --git a/src/test/ui/argument-suggestions/permuted_arguments.stderr b/src/test/ui/argument-suggestions/permuted_arguments.stderr new file mode 100644 index 000000000..f16d22860 --- /dev/null +++ b/src/test/ui/argument-suggestions/permuted_arguments.stderr @@ -0,0 +1,43 @@ +error[E0308]: arguments to this function are incorrect + --> $DIR/permuted_arguments.rs:10:3 + | +LL | three_args(1.0, "", 1); + | ^^^^^^^^^^ --- -- - expected `&str`, found `{integer}` + | | | + | | expected `f32`, found `&'static str` + | expected `i32`, found `{float}` + | +note: function defined here + --> $DIR/permuted_arguments.rs:5:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: reorder these arguments + | +LL | three_args(1, 1.0, ""); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/permuted_arguments.rs:12:3 + | +LL | many_args(X {}, Y {}, 1, 1.0, ""); + | ^^^^^^^^^ ---- ---- - --- -- expected `Y`, found `&'static str` + | | | | | + | | | | expected `X`, found `{float}` + | | | expected `&str`, found `{integer}` + | | expected `f32`, found `Y` + | expected `i32`, found `X` + | +note: function defined here + --> $DIR/permuted_arguments.rs:6:4 + | +LL | fn many_args(_a: i32, _b: f32, _c: &str, _d: X, _e: Y) {} + | ^^^^^^^^^ ------- ------- -------- ----- ----- +help: reorder these arguments + | +LL | many_args(1, 1.0, "", X {}, Y {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/argument-suggestions/swapped_arguments.rs b/src/test/ui/argument-suggestions/swapped_arguments.rs new file mode 100644 index 000000000..a21de610c --- /dev/null +++ b/src/test/ui/argument-suggestions/swapped_arguments.rs @@ -0,0 +1,14 @@ +struct X {} + +fn two_args(_a: i32, _b: f32) {} +fn three_args(_a: i32, _b: f32, _c: &str) {} +fn four_args(_a: i32, _b: f32, _c: &str, _d: X) {} + +fn main() { + two_args(1.0, 1); //~ ERROR arguments to this function are incorrect + three_args(1.0, 1, ""); //~ ERROR arguments to this function are incorrect + three_args( 1, "", 1.0); //~ ERROR arguments to this function are incorrect + three_args( "", 1.0, 1); //~ ERROR arguments to this function are incorrect + + four_args(1.0, 1, X {}, ""); //~ ERROR arguments to this function are incorrect +} diff --git a/src/test/ui/argument-suggestions/swapped_arguments.stderr b/src/test/ui/argument-suggestions/swapped_arguments.stderr new file mode 100644 index 000000000..a90792d0c --- /dev/null +++ b/src/test/ui/argument-suggestions/swapped_arguments.stderr @@ -0,0 +1,95 @@ +error[E0308]: arguments to this function are incorrect + --> $DIR/swapped_arguments.rs:8:3 + | +LL | two_args(1.0, 1); + | ^^^^^^^^ --- - expected `f32`, found `{integer}` + | | + | expected `i32`, found `{float}` + | +note: function defined here + --> $DIR/swapped_arguments.rs:3:4 + | +LL | fn two_args(_a: i32, _b: f32) {} + | ^^^^^^^^ ------- ------- +help: swap these arguments + | +LL | two_args(1, 1.0); + | ~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/swapped_arguments.rs:9:3 + | +LL | three_args(1.0, 1, ""); + | ^^^^^^^^^^ --- - expected `f32`, found `{integer}` + | | + | expected `i32`, found `{float}` + | +note: function defined here + --> $DIR/swapped_arguments.rs:4:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: swap these arguments + | +LL | three_args(1, 1.0, ""); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/swapped_arguments.rs:10:3 + | +LL | three_args( 1, "", 1.0); + | ^^^^^^^^^^ -- --- expected `&str`, found `{float}` + | | + | expected `f32`, found `&'static str` + | +note: function defined here + --> $DIR/swapped_arguments.rs:4:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: swap these arguments + | +LL | three_args(1, 1.0, ""); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/swapped_arguments.rs:11:3 + | +LL | three_args( "", 1.0, 1); + | ^^^^^^^^^^ -- - expected `&str`, found `{integer}` + | | + | expected `i32`, found `&'static str` + | +note: function defined here + --> $DIR/swapped_arguments.rs:4:4 + | +LL | fn three_args(_a: i32, _b: f32, _c: &str) {} + | ^^^^^^^^^^ ------- ------- -------- +help: swap these arguments + | +LL | three_args(1, 1.0, ""); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/swapped_arguments.rs:13:3 + | +LL | four_args(1.0, 1, X {}, ""); + | ^^^^^^^^^ --- - ---- -- expected `X`, found `&'static str` + | | | | + | | | expected `&str`, found `X` + | | expected `f32`, found `{integer}` + | expected `i32`, found `{float}` + | +note: function defined here + --> $DIR/swapped_arguments.rs:5:4 + | +LL | fn four_args(_a: i32, _b: f32, _c: &str, _d: X) {} + | ^^^^^^^^^ ------- ------- -------- ----- +help: did you mean + | +LL | four_args(1, 1.0, "", X {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0308`. |