diff options
| author | Rob Pilling <robpilling@gmail.com> | 2021-12-05 21:41:33 +0000 |
|---|---|---|
| committer | Rob Pilling <robpilling@gmail.com> | 2022-01-25 22:51:19 +0000 |
| commit | 54d2d30662c2832554bb127f017f7a311bb62b4e (patch) | |
| tree | a19c767d98cfa7d68e24b72bc678365f00b32472 /src/test | |
| parent | 80059f99424c64d10f073ab5c502856d46b1c26d (diff) | |
Compare tuple element & arg types before suggesting a tuple
Diffstat (limited to 'src/test')
5 files changed, 48 insertions, 10 deletions
diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.rs b/src/test/ui/suggestions/args-instead-of-tuple-errors.rs new file mode 100644 index 00000000000..c4e9c68e219 --- /dev/null +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.rs @@ -0,0 +1,13 @@ +// Ensure we don't suggest tuple-wrapping when we'd end up with a type error + +fn main() { + // we shouldn't suggest to fix these - `2` isn't a `bool` + + let _: Option<(i32, bool)> = Some(1, 2); + //~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied + int_bool(1, 2); + //~^ ERROR this function takes 1 argument but 2 arguments were supplied +} + +fn int_bool(_: (i32, bool)) { +} diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr new file mode 100644 index 00000000000..c53c8bbdcc9 --- /dev/null +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr @@ -0,0 +1,25 @@ +error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple-errors.rs:6:34 + | +LL | let _: Option<(i32, bool)> = Some(1, 2); + | ^^^^ - - supplied 2 arguments + | | + | expected 1 argument + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple-errors.rs:8:5 + | +LL | int_bool(1, 2); + | ^^^^^^^^ - - supplied 2 arguments + | | + | expected 1 argument + | +note: function defined here + --> $DIR/args-instead-of-tuple-errors.rs:12:4 + | +LL | fn int_bool(_: (i32, bool)) { + | ^^^^^^^^ -------------- + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0061`. diff --git a/src/test/ui/suggestions/args-instead-of-tuple.fixed b/src/test/ui/suggestions/args-instead-of-tuple.fixed index adb832b8a7b..095be95f185 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.fixed +++ b/src/test/ui/suggestions/args-instead-of-tuple.fixed @@ -11,8 +11,8 @@ fn main() { let _: Option<()> = Some(()); //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied - f((1, 2)); //~ ERROR this function takes 1 argument + two_ints((1, 2)); //~ ERROR this function takes 1 argument } -fn f(_: (i32, i32)) { +fn two_ints(_: (i32, i32)) { } diff --git a/src/test/ui/suggestions/args-instead-of-tuple.rs b/src/test/ui/suggestions/args-instead-of-tuple.rs index 8dbc58daeb1..3466a46df84 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.rs +++ b/src/test/ui/suggestions/args-instead-of-tuple.rs @@ -11,8 +11,8 @@ fn main() { let _: Option<()> = Some(); //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied - f(1, 2); //~ ERROR this function takes 1 argument + two_ints(1, 2); //~ ERROR this function takes 1 argument } -fn f(_: (i32, i32)) { +fn two_ints(_: (i32, i32)) { } diff --git a/src/test/ui/suggestions/args-instead-of-tuple.stderr b/src/test/ui/suggestions/args-instead-of-tuple.stderr index 95bbbdb2749..1bf7e7a8d17 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple.stderr @@ -34,18 +34,18 @@ 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 +LL | two_ints(1, 2); + | ^^^^^^^^ - - supplied 2 arguments | note: function defined here --> $DIR/args-instead-of-tuple.rs:17:4 | -LL | fn f(_: (i32, i32)) { - | ^ ------------- +LL | fn two_ints(_: (i32, i32)) { + | ^^^^^^^^ ------------- help: use parentheses to construct a tuple | -LL | f((1, 2)); - | + + +LL | two_ints((1, 2)); + | + + error: aborting due to 4 previous errors |
