diff --git a/tests/ui/suggestions/incorrect-variant-literal.rs b/tests/ui/suggestions/incorrect-variant-literal.rs new file mode 100644 index 00000000000..aac2cc54904 --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-literal.rs @@ -0,0 +1,55 @@ +//@ only-linux +//@ compile-flags: --error-format=human --color=always + +enum Enum { + Unit, + Tuple(i32), + Struct { x: i32 }, +} + +fn main() { + Enum::Unit; + Enum::Tuple; + Enum::Struct; + Enum::Unit(); + Enum::Tuple(); + Enum::Struct(); + Enum::Unit {}; + Enum::Tuple {}; + Enum::Struct {}; + Enum::Unit(0); + Enum::Tuple(0); + Enum::Struct(0); + Enum::Unit { x: 0 }; + Enum::Tuple { x: 0 }; + Enum::Struct { x: 0 }; // ok + Enum::Unit(0, 0); + Enum::Tuple(0, 0); + Enum::Struct(0, 0); + Enum::Unit { x: 0, y: 0 }; + + Enum::Tuple { x: 0, y: 0 }; + + Enum::Struct { x: 0, y: 0 }; + Enum::unit; + Enum::tuple; + Enum::r#struct; + Enum::unit(); + Enum::tuple(); + Enum::r#struct(); + Enum::unit {}; + Enum::tuple {}; + Enum::r#struct {}; + Enum::unit(0); + Enum::tuple(0); + Enum::r#struct(0); + Enum::unit { x: 0 }; + Enum::tuple { x: 0 }; + Enum::r#struct { x: 0 }; + Enum::unit(0, 0); + Enum::tuple(0, 0); + Enum::r#struct(0, 0); + Enum::unit { x: 0, y: 0 }; + Enum::tuple { x: 0, y: 0 }; + Enum::r#struct { x: 0, y: 0 }; +} diff --git a/tests/ui/suggestions/incorrect-variant-literal.svg b/tests/ui/suggestions/incorrect-variant-literal.svg new file mode 100644 index 00000000000..7d5353d02a7 --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-literal.svg @@ -0,0 +1,850 @@ + + + + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-literal.rs:13:5 + + | + + LL | Enum::Struct; + + | ^^^^^^^^^^^^ not a value + + + + error[E0618]: expected function, found enum variant `Enum::Unit` + + --> $DIR/incorrect-variant-literal.rs:14:5 + + | + + LL | Unit, + + | ---- enum variant `Enum::Unit` defined here + + ... + + LL | Enum::Unit(); + + | ^^^^^^^^^^-- + + | | + + | call expression requires function + + | + + help: `Enum::Unit` is a unit enum variant, and does not take parentheses to be constructed + + | + + LL - Enum::Unit(); + + LL + Enum::Unit; + + | + + + + error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied + + --> $DIR/incorrect-variant-literal.rs:15:5 + + | + + LL | Enum::Tuple(); + + | ^^^^^^^^^^^-- argument #1 of type `i32` is missing + + | + + note: tuple variant defined here + + --> $DIR/incorrect-variant-literal.rs:6:5 + + | + + LL | Tuple(i32), + + | ^^^^^ + + help: provide the argument + + | + + LL | Enum::Tuple(/* i32 */); + + | ~~~~~~~~~~~ + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-literal.rs:16:5 + + | + + LL | Enum::Struct(); + + | ^^^^^^^^^^^^ not a value + + + + error[E0063]: missing field `0` in initializer of `Enum` + + --> $DIR/incorrect-variant-literal.rs:18:5 + + | + + LL | Enum::Tuple {}; + + | ^^^^^^^^^^^ missing `0` + + + + error[E0063]: missing field `x` in initializer of `Enum` + + --> $DIR/incorrect-variant-literal.rs:19:5 + + | + + LL | Enum::Struct {}; + + | ^^^^^^^^^^^^ missing `x` + + + + error[E0618]: expected function, found `Enum` + + --> $DIR/incorrect-variant-literal.rs:20:5 + + | + + LL | Unit, + + | ---- `Enum::Unit` defined here + + ... + + LL | Enum::Unit(0); + + | ^^^^^^^^^^--- + + | | + + | call expression requires function + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-literal.rs:22:5 + + | + + LL | Enum::Struct(0); + + | ^^^^^^^^^^^^ not a value + + + + error[E0559]: variant `Enum::Unit` has no field named `x` + + --> $DIR/incorrect-variant-literal.rs:23:18 + + | + + LL | Enum::Unit { x: 0 }; + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Tuple` has no field named `x` + + --> $DIR/incorrect-variant-literal.rs:24:19 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | Enum::Tuple { x: 0 }; + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL | Enum::Tuple(/* fields */); + + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + error[E0618]: expected function, found `Enum` + + --> $DIR/incorrect-variant-literal.rs:26:5 + + | + + LL | Unit, + + | ---- `Enum::Unit` defined here + + ... + + LL | Enum::Unit(0, 0); + + | ^^^^^^^^^^------ + + | | + + | call expression requires function + + + + error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied + + --> $DIR/incorrect-variant-literal.rs:27:5 + + | + + LL | Enum::Tuple(0, 0); + + | ^^^^^^^^^^^ - unexpected argument #2 of type `{integer}` + + | + + note: tuple variant defined here + + --> $DIR/incorrect-variant-literal.rs:6:5 + + | + + LL | Tuple(i32), + + | ^^^^^ + + help: remove the extra argument + + | + + LL - Enum::Tuple(0, 0); + + LL + Enum::Tuple(0); + + | + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-literal.rs:28:5 + + | + + LL | Enum::Struct(0, 0); + + | ^^^^^^^^^^^^ not a value + + + + error[E0559]: variant `Enum::Unit` has no field named `x` + + --> $DIR/incorrect-variant-literal.rs:29:18 + + | + + LL | Enum::Unit { x: 0, y: 0 }; + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Unit` has no field named `y` + + --> $DIR/incorrect-variant-literal.rs:29:24 + + | + + LL | Enum::Unit { x: 0, y: 0 }; + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Tuple` has no field named `x` + + --> $DIR/incorrect-variant-literal.rs:31:19 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | Enum::Tuple { x: 0, y: 0 }; + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL | Enum::Tuple(/* fields */); + + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + error[E0559]: variant `Enum::Tuple` has no field named `y` + + --> $DIR/incorrect-variant-literal.rs:31:25 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | Enum::Tuple { x: 0, y: 0 }; + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL | Enum::Tuple(/* fields */); + + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + error[E0559]: variant `Enum::Struct` has no field named `y` + + --> $DIR/incorrect-variant-literal.rs:33:26 + + | + + LL | Enum::Struct { x: 0, y: 0 }; + + | ^ `Enum::Struct` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:34:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | Enum::unit; + + | ^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:35:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | Enum::tuple; + + | ^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:36:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | Enum::r#struct; + + | ^^^^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:37:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | Enum::unit(); + + | ^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:38:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | Enum::tuple(); + + | ^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:39:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | Enum::r#struct(); + + | ^^^^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:40:11 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | Enum::unit {}; + + | ^^^^ help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:41:11 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | Enum::tuple {}; + + | ^^^^^ help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:42:11 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | Enum::r#struct {}; + + | ^^^^^^^^ help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:43:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | Enum::unit(0); + + | ^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:44:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | Enum::tuple(0); + + | ^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:45:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | Enum::r#struct(0); + + | ^^^^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:46:11 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | Enum::unit { x: 0 }; + + | ^^^^ help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:47:11 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | Enum::tuple { x: 0 }; + + | ^^^^^ help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:48:11 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | Enum::r#struct { x: 0 }; + + | ^^^^^^^^ help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:49:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | Enum::unit(0, 0); + + | ^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:50:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | Enum::tuple(0, 0); + + | ^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-literal.rs:51:11 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | Enum::r#struct(0, 0); + + | ^^^^^^^^ + + | | + + | variant or associated item not found in `Enum` + + | help: there is a variant with a similar name: `Struct` + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:52:11 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | Enum::unit { x: 0, y: 0 }; + + | ^^^^ help: there is a variant with a similar name (notice the capitalization): `Unit` + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:53:11 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | Enum::tuple { x: 0, y: 0 }; + + | ^^^^^ help: there is a variant with a similar name: `Tuple` + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-literal.rs:54:11 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | Enum::r#struct { x: 0, y: 0 }; + + | ^^^^^^^^ help: there is a variant with a similar name: `Struct` + + + + error: aborting due to 39 previous errors + + + + Some errors have detailed explanations: E0061, E0063, E0533, E0559, E0599, E0618. + + For more information about an error, try `rustc --explain E0061`. + + + + + +