]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/associated-const-match-patterns.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / associated-const-match-patterns.rs
CommitLineData
d9579d0f
AL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
7453a54e
SL
11// aux-build:empty-struct.rs
12
d9579d0f
AL
13#![feature(associated_consts)]
14
7453a54e
SL
15extern crate empty_struct;
16use empty_struct::XEmpty2 as XFoo;
17
d9579d0f
AL
18struct Foo;
19
54a0048b 20#[derive(PartialEq, Eq)]
d9579d0f
AL
21enum Bar {
22 Var1,
23 Var2,
24}
25
26// Use inherent and trait impls to test UFCS syntax.
27impl Foo {
28 const MYBAR: Bar = Bar::Var2;
29}
30
31trait HasBar {
32 const THEBAR: Bar;
33}
34
35impl HasBar for Foo {
36 const THEBAR: Bar = Bar::Var1;
37}
38
7453a54e
SL
39impl HasBar for XFoo {
40 const THEBAR: Bar = Bar::Var1;
41}
42
d9579d0f
AL
43fn main() {
44 // Inherent impl
45 assert!(match Bar::Var2 {
46 Foo::MYBAR => true,
47 _ => false,
48 });
49 assert!(match Bar::Var2 {
50 <Foo>::MYBAR => true,
51 _ => false,
52 });
53 // Trait impl
54 assert!(match Bar::Var1 {
55 Foo::THEBAR => true,
56 _ => false,
57 });
58 assert!(match Bar::Var1 {
59 <Foo>::THEBAR => true,
60 _ => false,
61 });
62 assert!(match Bar::Var1 {
63 <Foo as HasBar>::THEBAR => true,
64 _ => false,
65 });
7453a54e
SL
66 assert!(match Bar::Var1 {
67 XFoo::THEBAR => true,
68 _ => false,
69 });
70 assert!(match Bar::Var1 {
71 <XFoo>::THEBAR => true,
72 _ => false,
73 });
74 assert!(match Bar::Var1 {
75 <XFoo as HasBar>::THEBAR => true,
76 _ => false,
77 });
d9579d0f 78}