diff options
| author | Rob Pilling <robpilling@gmail.com> | 2021-11-09 23:20:26 +0000 |
|---|---|---|
| committer | Rob Pilling <robpilling@gmail.com> | 2022-01-25 22:51:18 +0000 |
| commit | 80059f99424c64d10f073ab5c502856d46b1c26d (patch) | |
| tree | 9f7518acbae0ea1fae947c15f82f7095a25969b0 /src/test/ui | |
| parent | 94c300a4522f3386546ba77a21865bb78fe9bba8 (diff) | |
| download | rust-80059f99424c64d10f073ab5c502856d46b1c26d.tar.gz rust-80059f99424c64d10f073ab5c502856d46b1c26d.zip | |
Test tuple suggestions, including tuple-as-function-argument
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/suggestions/args-instead-of-tuple.fixed | 18 | ||||
| -rw-r--r-- | src/test/ui/suggestions/args-instead-of-tuple.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/suggestions/args-instead-of-tuple.stderr | 52 |
3 files changed, 88 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/args-instead-of-tuple.fixed b/src/test/ui/suggestions/args-instead-of-tuple.fixed new file mode 100644 index 00000000000..adb832b8a7b --- /dev/null +++ b/src/test/ui/suggestions/args-instead-of-tuple.fixed @@ -0,0 +1,18 @@ +// Test suggesting tuples where bare arguments may have been passed +// See issue #86481 for details. + +// run-rustfix + +fn main() { + let _: Result<(i32, i8), ()> = Ok((1, 2)); + //~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied + let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi")); + //~^ ERROR this enum variant takes 1 argument but 3 arguments were supplied + let _: Option<()> = Some(()); + //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied + + f((1, 2)); //~ ERROR this function takes 1 argument +} + +fn f(_: (i32, i32)) { +} diff --git a/src/test/ui/suggestions/args-instead-of-tuple.rs b/src/test/ui/suggestions/args-instead-of-tuple.rs new file mode 100644 index 00000000000..8dbc58daeb1 --- /dev/null +++ b/src/test/ui/suggestions/args-instead-of-tuple.rs @@ -0,0 +1,18 @@ +// Test suggesting tuples where bare arguments may have been passed +// See issue #86481 for details. + +// run-rustfix + +fn main() { + let _: Result<(i32, i8), ()> = Ok(1, 2); + //~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied + let _: Option<(i32, i8, &'static str)> = Some(1, 2, "hi"); + //~^ ERROR this enum variant takes 1 argument but 3 arguments were supplied + let _: Option<()> = Some(); + //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied + + f(1, 2); //~ ERROR this function takes 1 argument +} + +fn f(_: (i32, i32)) { +} diff --git a/src/test/ui/suggestions/args-instead-of-tuple.stderr b/src/test/ui/suggestions/args-instead-of-tuple.stderr new file mode 100644 index 00000000000..95bbbdb2749 --- /dev/null +++ b/src/test/ui/suggestions/args-instead-of-tuple.stderr @@ -0,0 +1,52 @@ +error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:7:36 + | +LL | let _: Result<(i32, i8), ()> = Ok(1, 2); + | ^^ - - supplied 2 arguments + | +help: use parentheses to construct a tuple + | +LL | let _: Result<(i32, i8), ()> = Ok((1, 2)); + | + + + +error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:9:46 + | +LL | let _: Option<(i32, i8, &'static str)> = Some(1, 2, "hi"); + | ^^^^ - - ---- supplied 3 arguments + | +help: use parentheses to construct a tuple + | +LL | let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi")); + | + + + +error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:11:25 + | +LL | let _: Option<()> = Some(); + | ^^^^-- supplied 0 arguments + | +help: expected the unit value `()`; create it with empty parentheses + | +LL | let _: Option<()> = Some(()); + | ++ + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:14:5 + | +LL | f(1, 2); + | ^ - - supplied 2 arguments + | +note: function defined here + --> $DIR/args-instead-of-tuple.rs:17:4 + | +LL | fn f(_: (i32, i32)) { + | ^ ------------- +help: use parentheses to construct a tuple + | +LL | f((1, 2)); + | + + + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0061`. |
