]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-consts/associated-const-match-patterns.rs
Rollup merge of #105983 - compiler-errors:issue-105981, r=tmiasko
[rust.git] / src / test / ui / associated-consts / associated-const-match-patterns.rs
1 // run-pass
2 // aux-build:empty-struct.rs
3
4
5 extern crate empty_struct;
6 use empty_struct::XEmpty2 as XFoo;
7
8 struct Foo;
9
10 #[derive(PartialEq, Eq)]
11 enum Bar {
12     Var1,
13     Var2,
14 }
15
16 // Use inherent and trait impls to test UFCS syntax.
17 impl Foo {
18     const MYBAR: Bar = Bar::Var2;
19 }
20
21 trait HasBar {
22     const THEBAR: Bar;
23 }
24
25 impl HasBar for Foo {
26     const THEBAR: Bar = Bar::Var1;
27 }
28
29 impl HasBar for XFoo {
30     const THEBAR: Bar = Bar::Var1;
31 }
32
33 fn main() {
34     // Inherent impl
35     assert!(match Bar::Var2 {
36         Foo::MYBAR => true,
37         _ => false,
38     });
39     assert!(match Bar::Var2 {
40         <Foo>::MYBAR => true,
41         _ => false,
42     });
43     // Trait impl
44     assert!(match Bar::Var1 {
45         Foo::THEBAR => true,
46         _ => false,
47     });
48     assert!(match Bar::Var1 {
49         <Foo>::THEBAR => true,
50         _ => false,
51     });
52     assert!(match Bar::Var1 {
53         <Foo as HasBar>::THEBAR => true,
54         _ => false,
55     });
56     assert!(match Bar::Var1 {
57         XFoo::THEBAR => true,
58         _ => false,
59     });
60     assert!(match Bar::Var1 {
61         <XFoo>::THEBAR => true,
62         _ => false,
63     });
64     assert!(match Bar::Var1 {
65         <XFoo as HasBar>::THEBAR => true,
66         _ => false,
67     });
68 }