]> git.proxmox.com Git - rustc.git/blame - src/test/ui/associated-consts/associated-const-match-patterns.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / associated-consts / associated-const-match-patterns.rs
CommitLineData
b7449926 1// run-pass
7453a54e
SL
2// aux-build:empty-struct.rs
3
d9579d0f 4
7453a54e
SL
5extern crate empty_struct;
6use empty_struct::XEmpty2 as XFoo;
7
d9579d0f
AL
8struct Foo;
9
54a0048b 10#[derive(PartialEq, Eq)]
d9579d0f
AL
11enum Bar {
12 Var1,
13 Var2,
14}
15
16// Use inherent and trait impls to test UFCS syntax.
17impl Foo {
18 const MYBAR: Bar = Bar::Var2;
19}
20
21trait HasBar {
22 const THEBAR: Bar;
23}
24
25impl HasBar for Foo {
26 const THEBAR: Bar = Bar::Var1;
27}
28
7453a54e
SL
29impl HasBar for XFoo {
30 const THEBAR: Bar = Bar::Var1;
31}
32
d9579d0f
AL
33fn 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 });
7453a54e
SL
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 });
d9579d0f 68}