type-alias-enum-variants-panic: harden + describe the test.

This commit is contained in:
Mazdak Farrokhzad 2019-06-09 05:52:55 +02:00
parent 77ff384865
commit bed189791e
2 changed files with 51 additions and 21 deletions

View File

@ -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]
}

View File

@ -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;
| ^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0164`.
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
Some errors have detailed explanations: E0164, E0618.
For more information about an error, try `rustc --explain E0164`.