diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-09 05:52:55 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-15 19:18:09 +0200 |
| commit | bed189791ef9b900788c40354a2ebe5d0427027a (patch) | |
| tree | e91e02d6ef771e3e4bbf086d9cb05c5f5c6cb1b1 | |
| parent | 77ff38486553f40dee1315ba5c1e8c92c3845403 (diff) | |
| download | rust-bed189791ef9b900788c40354a2ebe5d0427027a.tar.gz rust-bed189791ef9b900788c40354a2ebe5d0427027a.zip | |
type-alias-enum-variants-panic: harden + describe the test.
| -rw-r--r-- | src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.rs | 22 | ||||
| -rw-r--r-- | src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.stderr | 50 |
2 files changed, 51 insertions, 21 deletions
diff --git a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.rs b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.rs index c75fe6a8fd9..f474c078ba4 100644 --- a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.rs +++ b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.rs @@ -1,15 +1,23 @@ // ignore-tidy-linelength +// Check that creating/matching on an enum variant through an alias with +// the wrong braced/unit form is caught as an error. + #![allow(unreachable_code)] -enum Enum { Variant {} } +enum Enum { Braced {}, Unit, Tuple() } type Alias = Enum; fn main() { - Alias::Variant; - //~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Variant` [E0533] - let Alias::Variant = panic!(); - //~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Variant` [E0533] - let Alias::Variant(..) = panic!(); - //~^ ERROR expected tuple struct/variant, found struct variant `<Alias>::Variant` [E0164] + Alias::Braced; + //~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Braced` [E0533] + let Alias::Braced = panic!(); + //~^ ERROR expected unit struct/variant or constant, found struct variant `<Alias>::Braced` [E0533] + let Alias::Braced(..) = panic!(); + //~^ ERROR expected tuple struct/variant, found struct variant `<Alias>::Braced` [E0164] + + Alias::Unit(); + //~^ ERROR expected function, found enum variant `<Alias>::Unit` + let Alias::Unit() = panic!(); + //~^ ERROR expected tuple struct/variant, found unit variant `<Alias>::Unit` [E0164] } diff --git a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.stderr b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.stderr index 7a17596cd4a..fcc13c0360d 100644 --- a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.stderr +++ b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-panic.stderr @@ -1,21 +1,43 @@ -error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Variant` - --> $DIR/type-alias-enum-variants-panic.rs:9:5 +error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Braced` + --> $DIR/type-alias-enum-variants-panic.rs:12:5 | -LL | Alias::Variant; - | ^^^^^^^^^^^^^^ +LL | Alias::Braced; + | ^^^^^^^^^^^^^ -error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Variant` - --> $DIR/type-alias-enum-variants-panic.rs:11:9 +error[E0533]: expected unit struct/variant or constant, found struct variant `<Alias>::Braced` + --> $DIR/type-alias-enum-variants-panic.rs:14:9 | -LL | let Alias::Variant = panic!(); - | ^^^^^^^^^^^^^^ +LL | let Alias::Braced = panic!(); + | ^^^^^^^^^^^^^ -error[E0164]: expected tuple struct/variant, found struct variant `<Alias>::Variant` - --> $DIR/type-alias-enum-variants-panic.rs:13:9 +error[E0164]: expected tuple struct/variant, found struct variant `<Alias>::Braced` + --> $DIR/type-alias-enum-variants-panic.rs:16:9 | -LL | let Alias::Variant(..) = panic!(); - | ^^^^^^^^^^^^^^^^^^ not a tuple variant or struct +LL | let Alias::Braced(..) = panic!(); + | ^^^^^^^^^^^^^^^^^ not a tuple variant or struct -error: aborting due to 3 previous errors +error[E0618]: expected function, found enum variant `<Alias>::Unit` + --> $DIR/type-alias-enum-variants-panic.rs:19:5 + | +LL | enum Enum { Braced {}, Unit, Tuple() } + | ---- `<Alias>::Unit` defined here +... +LL | Alias::Unit(); + | ^^^^^^^^^^^-- + | | + | call expression requires function +help: `<Alias>::Unit` is a unit variant, you need to write it without the parenthesis + | +LL | <Alias>::Unit; + | ^^^^^^^^^^^^^ + +error[E0164]: expected tuple struct/variant, found unit variant `<Alias>::Unit` + --> $DIR/type-alias-enum-variants-panic.rs:21:9 + | +LL | let Alias::Unit() = panic!(); + | ^^^^^^^^^^^^^ not a tuple variant or struct + +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0164`. +Some errors have detailed explanations: E0164, E0618. +For more information about an error, try `rustc --explain E0164`. |
