]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/stmt_expr_attrs_no_feature.rs
2fda2ee0900c7470ea82f045817f7cd223e54532
[rust.git] / src / test / compile-fail / stmt_expr_attrs_no_feature.rs
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
11 #![feature(custom_attribute)]
12 #![feature(associated_consts)]
13
14 macro_rules! stmt_mac {
15     () => {
16         fn b() {}
17     }
18 }
19
20 fn main() {
21     #[attr]
22     fn a() {}
23
24     #[attr]
25     {
26
27     }
28
29     #[attr]
30     5;
31
32     #[attr]
33     stmt_mac!();
34 }
35
36 // Check that cfg works right
37
38 #[cfg(unset)]
39 fn c() {
40     #[attr]
41     5;
42 }
43
44 #[cfg(not(unset))]
45 fn j() {
46     #[attr]
47     5;
48 }
49
50 #[cfg_attr(not(unset), cfg(unset))]
51 fn d() {
52     #[attr]
53     8;
54 }
55
56 #[cfg_attr(not(unset), cfg(not(unset)))]
57 fn i() {
58     #[attr]
59     8;
60 }
61
62 // check that macro expansion and cfg works right
63
64 macro_rules! item_mac {
65     ($e:ident) => {
66         fn $e() {
67             #[attr]
68             42;
69
70             #[cfg(unset)]
71             fn f() {
72                 #[attr]
73                 5;
74             }
75
76             #[cfg(not(unset))]
77             fn k() {
78                 #[attr]
79                 5;
80             }
81
82             #[cfg_attr(not(unset), cfg(unset))]
83             fn g() {
84                 #[attr]
85                 8;
86             }
87
88             #[cfg_attr(not(unset), cfg(not(unset)))]
89             fn h() {
90                 #[attr]
91                 8;
92             }
93
94         }
95     }
96 }
97
98 item_mac!(e);
99
100 // check that the gate visitor works right:
101
102 extern {
103     #[cfg(unset)]
104     fn x(a: [u8; #[attr] 5]);
105     fn y(a: [u8; #[attr] 5]); //~ ERROR 15701
106 }
107
108 struct Foo;
109 impl Foo {
110     #[cfg(unset)]
111     const X: u8 = #[attr] 5;
112     const Y: u8 = #[attr] 5; //~ ERROR 15701
113 }
114
115 trait Bar {
116     #[cfg(unset)]
117     const X: [u8; #[attr] 5];
118     const Y: [u8; #[attr] 5]; //~ ERROR 15701
119 }
120
121 struct Joyce {
122     #[cfg(unset)]
123     field: [u8; #[attr] 5],
124     field2: [u8; #[attr] 5] //~ ERROR 15701
125 }
126
127 struct Walky(
128     #[cfg(unset)] [u8; #[attr] 5],
129     [u8; #[attr] 5] //~ ERROR 15701
130 );
131
132 enum Mike {
133     Happy(
134         #[cfg(unset)] [u8; #[attr] 5],
135         [u8; #[attr] 5] //~ ERROR 15701
136     ),
137     Angry {
138         #[cfg(unset)]
139         field: [u8; #[attr] 5],
140         field2: [u8; #[attr] 5] //~ ERROR 15701
141     }
142 }
143
144 fn pat() {
145     match 5 {
146         #[cfg(unset)]
147         5 => #[attr] (),
148         6 => #[attr] (), //~ ERROR 15701
149         _ => (),
150     }
151 }