summaryrefslogtreecommitdiffstats
path: root/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs')
-rw-r--r--tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs105
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs
new file mode 100644
index 000000000..0031a4665
--- /dev/null
+++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs
@@ -0,0 +1,105 @@
+// Checks that applied type arguments of enums, and aliases to them, are respected.
+// For example, `Self` is never a type constructor. Therefore, no types can be applied to it.
+//
+// We also check that the variant to an type-aliased enum cannot be type applied whether
+// that alias is generic or monomorphic.
+
+enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant }
+type Alias<T> = Enum<T>;
+type AliasFixed = Enum<()>;
+
+impl<T> Enum<T> {
+ fn ts_variant() {
+ Self::TSVariant(());
+ //~^ ERROR mismatched types [E0308]
+ Self::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ Self::<()>::TSVariant(());
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ //~| ERROR mismatched types [E0308]
+ Self::<()>::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ //~| ERROR type arguments are not allowed on this type [E0109]
+ }
+
+ fn s_variant() {
+ Self::SVariant { v: () };
+ //~^ ERROR mismatched types [E0308]
+ Self::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ //~| ERROR mismatched types [E0308]
+ Self::<()>::SVariant { v: () };
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ //~| ERROR mismatched types [E0308]
+ Self::<()>::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ //~| ERROR type arguments are not allowed on this type [E0109]
+ //~| ERROR mismatched types [E0308]
+ }
+
+ fn u_variant() {
+ Self::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ Self::<()>::UVariant;
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ Self::<()>::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on self type [E0109]
+ //~| ERROR type arguments are not allowed on this type [E0109]
+ }
+}
+
+fn main() {
+ // Tuple struct variant
+
+ Enum::<()>::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109]
+
+ Alias::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ Alias::<()>::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+
+ AliasFixed::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ AliasFixed::<()>::TSVariant(());
+ //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+ AliasFixed::<()>::TSVariant::<()>(());
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+
+ // Struct variant
+
+ Enum::<()>::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on variant `SVariant` [E0109]
+
+ Alias::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ Alias::<()>::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+
+ AliasFixed::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ AliasFixed::<()>::SVariant { v: () };
+ //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+ AliasFixed::<()>::SVariant::<()> { v: () };
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+
+ // Unit variant
+
+ Enum::<()>::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109]
+
+ Alias::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ Alias::<()>::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+
+ AliasFixed::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ AliasFixed::<()>::UVariant;
+ //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+ AliasFixed::<()>::UVariant::<()>;
+ //~^ ERROR type arguments are not allowed on this type [E0109]
+ //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
+}