diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/argument-suggestions | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/argument-suggestions')
46 files changed, 2275 insertions, 0 deletions
diff --git a/tests/ui/argument-suggestions/basic.rs b/tests/ui/argument-suggestions/basic.rs new file mode 100644 index 000000000..961e7a50e --- /dev/null +++ b/tests/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 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 function takes +} diff --git a/tests/ui/argument-suggestions/basic.stderr b/tests/ui/argument-suggestions/basic.stderr new file mode 100644 index 000000000..062b37688 --- /dev/null +++ b/tests/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(/* x */); + | ~~~~~~~~~ + +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/tests/ui/argument-suggestions/complex.rs b/tests/ui/argument-suggestions/complex.rs new file mode 100644 index 000000000..384cdca7e --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/complex.stderr b/tests/ui/argument-suggestions/complex.stderr new file mode 100644 index 000000000..205a85298 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/display-is-suggestable.rs b/tests/ui/argument-suggestions/display-is-suggestable.rs new file mode 100644 index 000000000..acb61f543 --- /dev/null +++ b/tests/ui/argument-suggestions/display-is-suggestable.rs @@ -0,0 +1,8 @@ +use std::fmt::Display; + +fn foo(x: &(dyn Display + Send)) {} + +fn main() { + foo(); + //~^ ERROR function takes 1 argument but 0 arguments were supplied +} diff --git a/tests/ui/argument-suggestions/display-is-suggestable.stderr b/tests/ui/argument-suggestions/display-is-suggestable.stderr new file mode 100644 index 000000000..edd72b53e --- /dev/null +++ b/tests/ui/argument-suggestions/display-is-suggestable.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/display-is-suggestable.rs:6:5 + | +LL | foo(); + | ^^^-- an argument of type `&dyn std::fmt::Display + Send` is missing + | +note: function defined here + --> $DIR/display-is-suggestable.rs:3:4 + | +LL | fn foo(x: &(dyn Display + Send)) {} + | ^^^ ------------------------ +help: provide the argument + | +LL | foo(/* &dyn std::fmt::Display + Send */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/argument-suggestions/exotic-calls.rs b/tests/ui/argument-suggestions/exotic-calls.rs new file mode 100644 index 000000000..569a39a2b --- /dev/null +++ b/tests/ui/argument-suggestions/exotic-calls.rs @@ -0,0 +1,26 @@ +fn foo<T: Fn()>(t: T) { + t(1i32); + //~^ ERROR function takes 0 arguments but 1 argument was supplied +} + +fn bar(t: impl Fn()) { + t(1i32); + //~^ ERROR function takes 0 arguments but 1 argument was supplied +} + +fn baz() -> impl Fn() { + || {} +} + +fn baz2() { + baz()(1i32) + //~^ ERROR function takes 0 arguments but 1 argument was supplied +} + +fn qux() { + let x = || {}; + x(1i32); + //~^ ERROR function takes 0 arguments but 1 argument was supplied +} + +fn main() {} diff --git a/tests/ui/argument-suggestions/exotic-calls.stderr b/tests/ui/argument-suggestions/exotic-calls.stderr new file mode 100644 index 000000000..0580e53c5 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/extern-fn-arg-names.rs b/tests/ui/argument-suggestions/extern-fn-arg-names.rs new file mode 100644 index 000000000..df2fd6624 --- /dev/null +++ b/tests/ui/argument-suggestions/extern-fn-arg-names.rs @@ -0,0 +1,9 @@ +extern "Rust" { + fn dstfn(src: i32, dst: err); + //~^ ERROR cannot find type `err` in this scope +} + +fn main() { + dstfn(1); + //~^ ERROR function takes 2 arguments but 1 argument was supplied +} diff --git a/tests/ui/argument-suggestions/extern-fn-arg-names.stderr b/tests/ui/argument-suggestions/extern-fn-arg-names.stderr new file mode 100644 index 000000000..f6bc84c12 --- /dev/null +++ b/tests/ui/argument-suggestions/extern-fn-arg-names.stderr @@ -0,0 +1,26 @@ +error[E0412]: cannot find type `err` in this scope + --> $DIR/extern-fn-arg-names.rs:2:29 + | +LL | fn dstfn(src: i32, dst: err); + | ^^^ not found in this scope + +error[E0061]: this function takes 2 arguments but 1 argument was supplied + --> $DIR/extern-fn-arg-names.rs:7:5 + | +LL | dstfn(1); + | ^^^^^--- an argument is missing + | +note: function defined here + --> $DIR/extern-fn-arg-names.rs:2:8 + | +LL | fn dstfn(src: i32, dst: err); + | ^^^^^ +help: provide the argument + | +LL | dstfn(1, /* dst */); + | ~~~~~~~~~~~~~~ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0061, E0412. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/argument-suggestions/extra_arguments.rs b/tests/ui/argument-suggestions/extra_arguments.rs new file mode 100644 index 000000000..3f83de95e --- /dev/null +++ b/tests/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 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 function takes + two_arg_same(1, 1, 1.0); //~ ERROR 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 function takes + two_arg_diff(1, 1, ""); //~ ERROR function takes + two_arg_same( //~ ERROR function takes + 1, + 1, + "" + ); + + two_arg_diff( //~ ERROR function takes + 1, + 1, + "" + ); +} diff --git a/tests/ui/argument-suggestions/extra_arguments.stderr b/tests/ui/argument-suggestions/extra_arguments.stderr new file mode 100644 index 000000000..48787b0c3 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/formal-and-expected-differ.rs b/tests/ui/argument-suggestions/formal-and-expected-differ.rs new file mode 100644 index 000000000..5e3b55ca5 --- /dev/null +++ b/tests/ui/argument-suggestions/formal-and-expected-differ.rs @@ -0,0 +1,25 @@ +pub trait Foo { + type T; +} + +impl Foo for i32 { + type T = f32; +} + +pub struct U<T1, T2>(T1, S<T2>) +where + T1: Foo<T = T2>; + +pub struct S<T>(T); + +fn main() { + // The error message here isn't great -- it has to do with the fact that the + // `expected_inputs_for_expected_output` deduced inputs differs from the inputs + // that we infer from the constraints of the signature. + // + // I am not really sure what the best way of presenting this error message is, + // since right now it just suggests changing `3u32` <=> `3f32` back and forth. + let _: U<_, u32> = U(1, S(3u32)); + //~^ ERROR mismatched types + //~| ERROR mismatched types +} diff --git a/tests/ui/argument-suggestions/formal-and-expected-differ.stderr b/tests/ui/argument-suggestions/formal-and-expected-differ.stderr new file mode 100644 index 000000000..905875b52 --- /dev/null +++ b/tests/ui/argument-suggestions/formal-and-expected-differ.stderr @@ -0,0 +1,30 @@ +error[E0308]: mismatched types + --> $DIR/formal-and-expected-differ.rs:22:29 + | +LL | let _: U<_, u32> = U(1, S(3u32)); + | - ^^^^^^^ expected `f32`, found `u32` + | | + | arguments to this struct are incorrect + | + = note: expected struct `S<f32>` + found struct `S<u32>` +note: tuple struct defined here + --> $DIR/formal-and-expected-differ.rs:9:12 + | +LL | pub struct U<T1, T2>(T1, S<T2>) + | ^ + +error[E0308]: mismatched types + --> $DIR/formal-and-expected-differ.rs:22:24 + | +LL | let _: U<_, u32> = U(1, S(3u32)); + | --------- ^^^^^^^^^^^^^ expected `u32`, found `f32` + | | + | expected due to this + | + = note: expected struct `U<_, u32>` + found struct `U<i32, f32>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/argument-suggestions/invalid_arguments.rs b/tests/ui/argument-suggestions/invalid_arguments.rs new file mode 100644 index 000000000..53fbdd4b5 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/invalid_arguments.stderr b/tests/ui/argument-suggestions/invalid_arguments.stderr new file mode 100644 index 000000000..303f08695 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/issue-100154.rs b/tests/ui/argument-suggestions/issue-100154.rs new file mode 100644 index 000000000..fb0af05e9 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-100154.rs @@ -0,0 +1,7 @@ +fn foo(i: impl std::fmt::Display) {} + +fn main() { + foo::<()>(()); + //~^ ERROR function takes 0 generic arguments but 1 generic argument was supplied + //~| ERROR `()` doesn't implement `std::fmt::Display` +} diff --git a/tests/ui/argument-suggestions/issue-100154.stderr b/tests/ui/argument-suggestions/issue-100154.stderr new file mode 100644 index 000000000..1499229c3 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/issue-100478.rs b/tests/ui/argument-suggestions/issue-100478.rs new file mode 100644 index 000000000..fb50fa115 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-100478.rs @@ -0,0 +1,52 @@ +use std::sync::Arc; +macro_rules! GenT { + ($name:tt) => { + #[derive(Default, Debug)] + struct $name { + #[allow(unused)] + val: i32, + } + + impl $name { + #[allow(unused)] + fn new(val: i32) -> Self { + $name { val } + } + } + }; +} + +GenT!(T1); +GenT!(T2); +GenT!(T3); +GenT!(T4); +GenT!(T5); +GenT!(T6); +GenT!(T7); +GenT!(T8); + +#[allow(unused)] +fn foo(p1: T1, p2: Arc<T2>, p3: T3, p4: Arc<T4>, p5: T5, p6: T6, p7: T7, p8: Arc<T8>) {} +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 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] + + let p1 = T1::new(0); + let p2 = Arc::new(T2::new(0)); + let p3 = T3::new(0); + let p4 = Arc::new(T4::new(1)); + let p5 = T5::new(0); + let p6 = T6::new(0); + let p7 = T7::new(0); + let p8 = Arc::default(); + + foo( + //~^ 47:5: 47:8: this function takes 8 arguments but 7 arguments were supplied [E0061] + p1, //p2, + p3, p4, p5, p6, p7, p8, + ); +} diff --git a/tests/ui/argument-suggestions/issue-100478.stderr b/tests/ui/argument-suggestions/issue-100478.stderr new file mode 100644 index 000000000..df02a312c --- /dev/null +++ b/tests/ui/argument-suggestions/issue-100478.stderr @@ -0,0 +1,81 @@ +error[E0061]: this function takes 3 arguments but 1 argument was supplied + --> $DIR/issue-100478.rs:34:5 + | +LL | three_diff(T2::new(0)); + | ^^^^^^^^^^------------ + | || + | |an argument of type `T1` is missing + | an argument of type `T3` is missing + | +note: function defined here + --> $DIR/issue-100478.rs:30:4 + | +LL | fn three_diff(_a: T1, _b: T2, _c: T3) {} + | ^^^^^^^^^^ ------ ------ ------ +help: provide the arguments + | +LL | three_diff(/* T1 */, T2::new(0), /* T3 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-100478.rs:35:5 + | +LL | four_shuffle(T3::default(), T4::default(), T1::default(), T2::default()); + | ^^^^^^^^^^^^ ------------- ------------- ------------- ------------- expected `T4`, found `T2` + | | | | + | | | expected `T3`, found `T1` + | | expected `T2`, found `T4` + | expected `T1`, found `T3` + | +note: function defined here + --> $DIR/issue-100478.rs:31:4 + | +LL | fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {} + | ^^^^^^^^^^^^ ------ ------ ------ ------ +help: did you mean + | +LL | four_shuffle(T1::default(), T2::default(), T3::default(), T4::default()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-100478.rs:36:5 + | +LL | four_shuffle(T3::default(), T2::default(), T1::default(), T3::default()); + | ^^^^^^^^^^^^ ------------- ------------- ------------- expected struct `T4`, found struct `T3` + | | | + | | expected `T3`, found `T1` + | expected `T1`, found `T3` + | +note: function defined here + --> $DIR/issue-100478.rs:31:4 + | +LL | fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {} + | ^^^^^^^^^^^^ ------ ------ ------ ------ +help: swap these arguments + | +LL | four_shuffle(T1::default(), T2::default(), T3::default(), /* T4 */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this function takes 8 arguments but 7 arguments were supplied + --> $DIR/issue-100478.rs:47:5 + | +LL | foo( + | ^^^ +... +LL | p3, p4, p5, p6, p7, p8, + | -- an argument of type `Arc<T2>` is missing + | +note: function defined here + --> $DIR/issue-100478.rs:29:4 + | +LL | fn foo(p1: T1, p2: Arc<T2>, p3: T3, p4: Arc<T4>, p5: T5, p6: T6, p7: T7, p8: Arc<T8>) {} + | ^^^ ------ ----------- ------ ----------- ------ ------ ------ ----------- +help: provide the argument + | +LL | foo(p1, /* Arc<T2> */, p3, p4, p5, p6, p7, p8); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0061, E0308. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/argument-suggestions/issue-101097.rs b/tests/ui/argument-suggestions/issue-101097.rs new file mode 100644 index 000000000..25f7f5837 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-101097.rs @@ -0,0 +1,21 @@ +struct A; +struct B; +struct C; +struct D; + +fn f( + a1: A, + a2: A, + b1: B, + b2: B, + c1: C, + c2: C, +) {} + +fn main() { + 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] + f(C, C, A, B, A, A); //~ arguments to this function are incorrect [E0308] +} diff --git a/tests/ui/argument-suggestions/issue-101097.stderr b/tests/ui/argument-suggestions/issue-101097.stderr new file mode 100644 index 000000000..096f8c226 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-101097.stderr @@ -0,0 +1,160 @@ +error[E0061]: this function takes 6 arguments but 7 arguments were supplied + --> $DIR/issue-101097.rs:16:5 + | +LL | f(C, A, A, A, B, B, C); + | ^ - - - - expected `C`, found `B` + | | | | + | | | argument of type `A` unexpected + | | expected `B`, found `A` + | expected `A`, found `C` + | +note: function defined here + --> $DIR/issue-101097.rs:6:4 + | +LL | fn f( + | ^ +LL | a1: A, + | ----- +LL | a2: A, + | ----- +LL | b1: B, + | ----- +LL | b2: B, + | ----- +LL | c1: C, + | ----- +LL | c2: C, + | ----- +help: did you mean + | +LL | f(A, A, B, B, C, C); + | ~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-101097.rs:17:5 + | +LL | f(C, C, A, A, B, B); + | ^ + | +note: function defined here + --> $DIR/issue-101097.rs:6:4 + | +LL | fn f( + | ^ +LL | a1: A, + | ----- +LL | a2: A, + | ----- +LL | b1: B, + | ----- +LL | b2: B, + | ----- +LL | c1: C, + | ----- +LL | c2: C, + | ----- +help: did you mean + | +LL | f(A, A, B, B, C, C); + | ~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-101097.rs:18:5 + | +LL | f(A, A, D, D, B, B); + | ^ - - ---- two arguments of type `C` and `C` are missing + | | | + | | argument of type `D` unexpected + | argument of type `D` unexpected + | +note: function defined here + --> $DIR/issue-101097.rs:6:4 + | +LL | fn f( + | ^ +LL | a1: A, + | ----- +LL | a2: A, + | ----- +LL | b1: B, + | ----- +LL | b2: B, + | ----- +LL | c1: C, + | ----- +LL | c2: C, + | ----- +help: did you mean + | +LL | f(A, A, B, B, /* C */, /* C */); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-101097.rs:19:5 + | +LL | f(C, C, B, B, A, A); + | ^ - - - - expected `C`, found `A` + | | | | + | | | expected `C`, found `A` + | | expected `A`, found `C` + | expected `A`, found `C` + | +note: function defined here + --> $DIR/issue-101097.rs:6:4 + | +LL | fn f( + | ^ +LL | a1: A, + | ----- +LL | a2: A, + | ----- +LL | b1: B, + | ----- +LL | b2: B, + | ----- +LL | c1: C, + | ----- +LL | c2: C, + | ----- +help: did you mean + | +LL | f(A, A, B, B, C, C); + | ~~~~~~~~~~~~~~~~~~ + +error[E0308]: arguments to this function are incorrect + --> $DIR/issue-101097.rs:20:5 + | +LL | f(C, C, A, B, A, A); + | ^ - - - - - expected `C`, found `A` + | | | | | + | | | | expected `C`, found `A` + | | | expected struct `B`, found struct `A` + | | expected `A`, found `C` + | expected `A`, found `C` + | +note: function defined here + --> $DIR/issue-101097.rs:6:4 + | +LL | fn f( + | ^ +LL | a1: A, + | ----- +LL | a2: A, + | ----- +LL | b1: B, + | ----- +LL | b2: B, + | ----- +LL | c1: C, + | ----- +LL | c2: C, + | ----- +help: did you mean + | +LL | f(A, A, /* B */, B, C, C); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0061, E0308. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/argument-suggestions/issue-96638.rs b/tests/ui/argument-suggestions/issue-96638.rs new file mode 100644 index 000000000..5e720f174 --- /dev/null +++ b/tests/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 function takes 3 arguments but 2 arguments were supplied +} diff --git a/tests/ui/argument-suggestions/issue-96638.stderr b/tests/ui/argument-suggestions/issue-96638.stderr new file mode 100644 index 000000000..4d18b97c9 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-96638.stderr @@ -0,0 +1,21 @@ +error[E0061]: this function takes 3 arguments but 2 arguments were supplied + --> $DIR/issue-96638.rs:8:5 + | +LL | f(&x, ""); + | ^ -- -- expected `usize`, found `&str` + | | + | 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/tests/ui/argument-suggestions/issue-97197.rs b/tests/ui/argument-suggestions/issue-97197.rs new file mode 100644 index 000000000..4c22608ae --- /dev/null +++ b/tests/ui/argument-suggestions/issue-97197.rs @@ -0,0 +1,6 @@ +fn main() { + g((), ()); + //~^ ERROR 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/tests/ui/argument-suggestions/issue-97197.stderr b/tests/ui/argument-suggestions/issue-97197.stderr new file mode 100644 index 000000000..de221ba1f --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/issue-97484.rs b/tests/ui/argument-suggestions/issue-97484.rs new file mode 100644 index 000000000..9e537b0c3 --- /dev/null +++ b/tests/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 function takes 4 arguments but 7 arguments were supplied +} diff --git a/tests/ui/argument-suggestions/issue-97484.stderr b/tests/ui/argument-suggestions/issue-97484.stderr new file mode 100644 index 000000000..caa50f14b --- /dev/null +++ b/tests/ui/argument-suggestions/issue-97484.stderr @@ -0,0 +1,27 @@ +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 + | | | | + | | | expected `&E`, found struct `E` + | | 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/tests/ui/argument-suggestions/issue-98894.rs b/tests/ui/argument-suggestions/issue-98894.rs new file mode 100644 index 000000000..e421eba97 --- /dev/null +++ b/tests/ui/argument-suggestions/issue-98894.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())(if true {} else {return;}); + //~^ ERROR function takes 2 arguments but 1 argument was supplied +} diff --git a/tests/ui/argument-suggestions/issue-98894.stderr b/tests/ui/argument-suggestions/issue-98894.stderr new file mode 100644 index 000000000..f64a83ab7 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/issue-98897.rs b/tests/ui/argument-suggestions/issue-98897.rs new file mode 100644 index 000000000..27734f74d --- /dev/null +++ b/tests/ui/argument-suggestions/issue-98897.rs @@ -0,0 +1,4 @@ +fn main() { + (|_, ()| ())([return, ()]); + //~^ ERROR function takes 2 arguments but 1 argument was supplied +} diff --git a/tests/ui/argument-suggestions/issue-98897.stderr b/tests/ui/argument-suggestions/issue-98897.stderr new file mode 100644 index 000000000..f2c47d353 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/issue-99482.rs b/tests/ui/argument-suggestions/issue-99482.rs new file mode 100644 index 000000000..7bbb39f8d --- /dev/null +++ b/tests/ui/argument-suggestions/issue-99482.rs @@ -0,0 +1,5 @@ +fn main() { + let f = |_: (), f: fn()| f; + let _f = f(main); + //~^ ERROR function takes 2 arguments but 1 argument was supplied +} diff --git a/tests/ui/argument-suggestions/issue-99482.stderr b/tests/ui/argument-suggestions/issue-99482.stderr new file mode 100644 index 000000000..bcf36e37c --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/missing_arguments.rs b/tests/ui/argument-suggestions/missing_arguments.rs new file mode 100644 index 000000000..c26564641 --- /dev/null +++ b/tests/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 function takes + // The headers here show the types expected, + // with formatting to emphasize which arguments are missing + /* i32 f32 */ + 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 function takes + three_same( 1 ); //~ ERROR function takes + three_same( 1, 1 ); //~ ERROR function takes + + /* i32 f32 &str */ + 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 function takes + four_repeated( 1, "" ); //~ ERROR function takes + + /* i32 f32 i32 f32 &str */ + complex( ); //~ ERROR function takes + complex( 1, "" ); //~ ERROR function takes +} diff --git a/tests/ui/argument-suggestions/missing_arguments.stderr b/tests/ui/argument-suggestions/missing_arguments.stderr new file mode 100644 index 000000000..ba9ece040 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/mixed_cases.rs b/tests/ui/argument-suggestions/mixed_cases.rs new file mode 100644 index 000000000..86e94a438 --- /dev/null +++ b/tests/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 function takes + three_args(1, "", X {}, ""); //~ ERROR function takes + + // Missing and Invalid + three_args(1, X {}); //~ ERROR 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 function takes +} diff --git a/tests/ui/argument-suggestions/mixed_cases.stderr b/tests/ui/argument-suggestions/mixed_cases.stderr new file mode 100644 index 000000000..8c525db1a --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/permuted_arguments.rs b/tests/ui/argument-suggestions/permuted_arguments.rs new file mode 100644 index 000000000..f512fde65 --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/permuted_arguments.stderr b/tests/ui/argument-suggestions/permuted_arguments.stderr new file mode 100644 index 000000000..655807a7f --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/swapped_arguments.rs b/tests/ui/argument-suggestions/swapped_arguments.rs new file mode 100644 index 000000000..a21de610c --- /dev/null +++ b/tests/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/tests/ui/argument-suggestions/swapped_arguments.stderr b/tests/ui/argument-suggestions/swapped_arguments.stderr new file mode 100644 index 000000000..dabf5e952 --- /dev/null +++ b/tests/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`. diff --git a/tests/ui/argument-suggestions/too-long.rs b/tests/ui/argument-suggestions/too-long.rs new file mode 100644 index 000000000..7ec56afae --- /dev/null +++ b/tests/ui/argument-suggestions/too-long.rs @@ -0,0 +1,41 @@ +struct Qux; + +impl Qux { + fn foo( + &self, + a: i32, + b: i32, + c: i32, + d: i32, + e: i32, + f: i32, + g: i32, + h: i32, + i: i32, + j: i32, + k: i32, + l: i32, + ) { + } +} + +fn what( + qux: &Qux, + a: i32, + b: i32, + c: i32, + d: i32, + e: i32, + f: &i32, + g: i32, + h: i32, + i: i32, + j: i32, + k: i32, + l: i32, +) { + qux.foo(a, b, c, d, e, f, g, h, i, j, k, l); + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/argument-suggestions/too-long.stderr b/tests/ui/argument-suggestions/too-long.stderr new file mode 100644 index 000000000..492894329 --- /dev/null +++ b/tests/ui/argument-suggestions/too-long.stderr @@ -0,0 +1,24 @@ +error[E0308]: mismatched types + --> $DIR/too-long.rs:37:28 + | +LL | qux.foo(a, b, c, d, e, f, g, h, i, j, k, l); + | --- ^ expected `i32`, found `&i32` + | | + | arguments to this method are incorrect + | +note: associated function defined here + --> $DIR/too-long.rs:4:8 + | +LL | fn foo( + | ^^^ +... +LL | f: i32, + | ------ +help: consider dereferencing the borrow + | +LL | qux.foo(a, b, c, d, e, *f, g, h, i, j, k, l); + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/argument-suggestions/two-mismatch-notes.rs b/tests/ui/argument-suggestions/two-mismatch-notes.rs new file mode 100644 index 000000000..1309041ab --- /dev/null +++ b/tests/ui/argument-suggestions/two-mismatch-notes.rs @@ -0,0 +1,11 @@ +#[derive(Copy, Clone)] +struct Wrapper<T>(T); + +fn foo(_: fn(i32), _: Wrapper<i32>) {} + +fn f(_: u32) {} + +fn main() { + let w = Wrapper::<isize>(1isize); + foo(f, w); //~ ERROR arguments to this function are incorrect +} diff --git a/tests/ui/argument-suggestions/two-mismatch-notes.stderr b/tests/ui/argument-suggestions/two-mismatch-notes.stderr new file mode 100644 index 000000000..7873cf964 --- /dev/null +++ b/tests/ui/argument-suggestions/two-mismatch-notes.stderr @@ -0,0 +1,29 @@ +error[E0308]: arguments to this function are incorrect + --> $DIR/two-mismatch-notes.rs:10:5 + | +LL | foo(f, w); + | ^^^ + | +note: expected `i32`, found `u32` + --> $DIR/two-mismatch-notes.rs:10:9 + | +LL | foo(f, w); + | ^ + = note: expected fn pointer `fn(i32)` + found fn item `fn(u32) {f}` +note: expected `i32`, found `isize` + --> $DIR/two-mismatch-notes.rs:10:12 + | +LL | foo(f, w); + | ^ + = note: expected struct `Wrapper<i32>` + found struct `Wrapper<isize>` +note: function defined here + --> $DIR/two-mismatch-notes.rs:4:4 + | +LL | fn foo(_: fn(i32), _: Wrapper<i32>) {} + | ^^^ ---------- --------------- + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |