summaryrefslogtreecommitdiffstats
path: root/tests/ui/variants
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/variants')
-rw-r--r--tests/ui/variants/auxiliary/variant-namespacing.rs5
-rw-r--r--tests/ui/variants/variant-namespacing.rs33
-rw-r--r--tests/ui/variants/variant-namespacing.stderr93
-rw-r--r--tests/ui/variants/variant-size-differences.rs8
-rw-r--r--tests/ui/variants/variant-size-differences.stderr14
-rw-r--r--tests/ui/variants/variant-used-as-type.rs20
-rw-r--r--tests/ui/variants/variant-used-as-type.stderr29
7 files changed, 202 insertions, 0 deletions
diff --git a/tests/ui/variants/auxiliary/variant-namespacing.rs b/tests/ui/variants/auxiliary/variant-namespacing.rs
new file mode 100644
index 000000000..7ba601a88
--- /dev/null
+++ b/tests/ui/variants/auxiliary/variant-namespacing.rs
@@ -0,0 +1,5 @@
+pub enum XE {
+ XStruct { a: u8 },
+ XTuple(u8),
+ XUnit,
+}
diff --git a/tests/ui/variants/variant-namespacing.rs b/tests/ui/variants/variant-namespacing.rs
new file mode 100644
index 000000000..975e471fe
--- /dev/null
+++ b/tests/ui/variants/variant-namespacing.rs
@@ -0,0 +1,33 @@
+// aux-build:variant-namespacing.rs
+
+pub enum E {
+ Struct { a: u8 },
+ Tuple(u8),
+ Unit,
+}
+
+type Struct = u8;
+type Tuple = u8;
+type Unit = u8;
+type XStruct = u8;
+type XTuple = u8;
+type XUnit = u8;
+
+const Struct: u8 = 0;
+const Tuple: u8 = 0;
+const Unit: u8 = 0;
+const XStruct: u8 = 0;
+const XTuple: u8 = 0;
+const XUnit: u8 = 0;
+
+extern crate variant_namespacing;
+pub use variant_namespacing::XE::{XStruct, XTuple, XUnit};
+//~^ ERROR the name `XStruct` is defined multiple times
+//~| ERROR the name `XTuple` is defined multiple times
+//~| ERROR the name `XUnit` is defined multiple times
+pub use E::{Struct, Tuple, Unit};
+//~^ ERROR the name `Struct` is defined multiple times
+//~| ERROR the name `Tuple` is defined multiple times
+//~| ERROR the name `Unit` is defined multiple times
+
+fn main() {}
diff --git a/tests/ui/variants/variant-namespacing.stderr b/tests/ui/variants/variant-namespacing.stderr
new file mode 100644
index 000000000..9e91ff717
--- /dev/null
+++ b/tests/ui/variants/variant-namespacing.stderr
@@ -0,0 +1,93 @@
+error[E0255]: the name `XStruct` is defined multiple times
+ --> $DIR/variant-namespacing.rs:24:35
+ |
+LL | type XStruct = u8;
+ | ------------------ previous definition of the type `XStruct` here
+...
+LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit};
+ | ^^^^^^^ `XStruct` reimported here
+ |
+ = note: `XStruct` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use variant_namespacing::XE::{XStruct as OtherXStruct, XTuple, XUnit};
+ | ~~~~~~~~~~~~~~~~~~~~~~~
+
+error[E0255]: the name `XTuple` is defined multiple times
+ --> $DIR/variant-namespacing.rs:24:44
+ |
+LL | type XTuple = u8;
+ | ----------------- previous definition of the type `XTuple` here
+...
+LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit};
+ | ^^^^^^ `XTuple` reimported here
+ |
+ = note: `XTuple` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use variant_namespacing::XE::{XStruct, XTuple as OtherXTuple, XUnit};
+ | ~~~~~~~~~~~~~~~~~~~~~
+
+error[E0255]: the name `XUnit` is defined multiple times
+ --> $DIR/variant-namespacing.rs:24:52
+ |
+LL | type XUnit = u8;
+ | ---------------- previous definition of the type `XUnit` here
+...
+LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit};
+ | ^^^^^ `XUnit` reimported here
+ |
+ = note: `XUnit` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit as OtherXUnit};
+ | ~~~~~~~~~~~~~~~~~~~
+
+error[E0255]: the name `Struct` is defined multiple times
+ --> $DIR/variant-namespacing.rs:28:13
+ |
+LL | type Struct = u8;
+ | ----------------- previous definition of the type `Struct` here
+...
+LL | pub use E::{Struct, Tuple, Unit};
+ | ^^^^^^ `Struct` reimported here
+ |
+ = note: `Struct` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use E::{Struct as OtherStruct, Tuple, Unit};
+ | ~~~~~~~~~~~~~~~~~~~~~
+
+error[E0255]: the name `Tuple` is defined multiple times
+ --> $DIR/variant-namespacing.rs:28:21
+ |
+LL | type Tuple = u8;
+ | ---------------- previous definition of the type `Tuple` here
+...
+LL | pub use E::{Struct, Tuple, Unit};
+ | ^^^^^ `Tuple` reimported here
+ |
+ = note: `Tuple` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use E::{Struct, Tuple as OtherTuple, Unit};
+ | ~~~~~~~~~~~~~~~~~~~
+
+error[E0255]: the name `Unit` is defined multiple times
+ --> $DIR/variant-namespacing.rs:28:28
+ |
+LL | type Unit = u8;
+ | --------------- previous definition of the type `Unit` here
+...
+LL | pub use E::{Struct, Tuple, Unit};
+ | ^^^^ `Unit` reimported here
+ |
+ = note: `Unit` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+ |
+LL | pub use E::{Struct, Tuple, Unit as OtherUnit};
+ | ~~~~~~~~~~~~~~~~~
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0255`.
diff --git a/tests/ui/variants/variant-size-differences.rs b/tests/ui/variants/variant-size-differences.rs
new file mode 100644
index 000000000..219819951
--- /dev/null
+++ b/tests/ui/variants/variant-size-differences.rs
@@ -0,0 +1,8 @@
+#![deny(variant_size_differences)]
+
+enum _En {
+ V0(u8),
+ VBig([u8; 1024]), //~ ERROR variant is more than three times larger
+}
+
+fn main() {}
diff --git a/tests/ui/variants/variant-size-differences.stderr b/tests/ui/variants/variant-size-differences.stderr
new file mode 100644
index 000000000..241a757d4
--- /dev/null
+++ b/tests/ui/variants/variant-size-differences.stderr
@@ -0,0 +1,14 @@
+error: enum variant is more than three times larger (1024 bytes) than the next largest
+ --> $DIR/variant-size-differences.rs:5:5
+ |
+LL | VBig([u8; 1024]),
+ | ^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/variant-size-differences.rs:1:9
+ |
+LL | #![deny(variant_size_differences)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/variants/variant-used-as-type.rs b/tests/ui/variants/variant-used-as-type.rs
new file mode 100644
index 000000000..f27db1024
--- /dev/null
+++ b/tests/ui/variants/variant-used-as-type.rs
@@ -0,0 +1,20 @@
+// Test error message when enum variants are used as types
+
+
+// issue 21225
+enum Ty {
+ A,
+ B(Ty::A),
+ //~^ ERROR expected type, found variant `Ty::A`
+}
+
+
+// issue 19197
+enum E {
+ A
+}
+
+impl E::A {}
+//~^ ERROR expected type, found variant `E::A`
+
+fn main() {}
diff --git a/tests/ui/variants/variant-used-as-type.stderr b/tests/ui/variants/variant-used-as-type.stderr
new file mode 100644
index 000000000..64424abbc
--- /dev/null
+++ b/tests/ui/variants/variant-used-as-type.stderr
@@ -0,0 +1,29 @@
+error[E0573]: expected type, found variant `Ty::A`
+ --> $DIR/variant-used-as-type.rs:7:7
+ |
+LL | B(Ty::A),
+ | ^^^^^ not a type
+ |
+help: try using the variant's enum
+ |
+LL | B(E),
+ | ~
+LL | B(Ty),
+ | ~~
+
+error[E0573]: expected type, found variant `E::A`
+ --> $DIR/variant-used-as-type.rs:17:6
+ |
+LL | impl E::A {}
+ | ^^^^ not a type
+ |
+help: try using the variant's enum
+ |
+LL | impl E {}
+ | ~
+LL | impl Ty {}
+ | ~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0573`.