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