summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-consts/associated-const-match-patterns.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/associated-consts/associated-const-match-patterns.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/associated-consts/associated-const-match-patterns.rs')
-rw-r--r--src/test/ui/associated-consts/associated-const-match-patterns.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/associated-consts/associated-const-match-patterns.rs b/src/test/ui/associated-consts/associated-const-match-patterns.rs
new file mode 100644
index 000000000..62c1cb983
--- /dev/null
+++ b/src/test/ui/associated-consts/associated-const-match-patterns.rs
@@ -0,0 +1,68 @@
+// run-pass
+// aux-build:empty-struct.rs
+
+
+extern crate empty_struct;
+use empty_struct::XEmpty2 as XFoo;
+
+struct Foo;
+
+#[derive(PartialEq, Eq)]
+enum Bar {
+ Var1,
+ Var2,
+}
+
+// Use inherent and trait impls to test UFCS syntax.
+impl Foo {
+ const MYBAR: Bar = Bar::Var2;
+}
+
+trait HasBar {
+ const THEBAR: Bar;
+}
+
+impl HasBar for Foo {
+ const THEBAR: Bar = Bar::Var1;
+}
+
+impl HasBar for XFoo {
+ const THEBAR: Bar = Bar::Var1;
+}
+
+fn main() {
+ // Inherent impl
+ assert!(match Bar::Var2 {
+ Foo::MYBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var2 {
+ <Foo>::MYBAR => true,
+ _ => false,
+ });
+ // Trait impl
+ assert!(match Bar::Var1 {
+ Foo::THEBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var1 {
+ <Foo>::THEBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var1 {
+ <Foo as HasBar>::THEBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var1 {
+ XFoo::THEBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var1 {
+ <XFoo>::THEBAR => true,
+ _ => false,
+ });
+ assert!(match Bar::Var1 {
+ <XFoo as HasBar>::THEBAR => true,
+ _ => false,
+ });
+}