]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/item-attributes.rs
ef825826ea4956b01dbb901579c8a2c4cc254d7c
[rust.git] / src / test / run-pass / item-attributes.rs
1 // Copyright 2012-2014 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 // These are attributes of the implicit crate. Really this just needs to parse
12 // for completeness since .rs files linked from .rc files support this
13 // notation to specify their module's attributes
14 #![attr1 = "val"]
15 #![attr2 = "val"]
16 #![attr3]
17 #![attr4(attr5)]
18
19 #![crate_id="foobar#0.1"]
20
21 // These are attributes of the following mod
22 #[attr1 = "val"]
23 #[attr2 = "val"]
24 mod test_first_item_in_file_mod {}
25
26 mod test_single_attr_outer {
27     #[attr = "val"]
28     pub static x: int = 10;
29
30     #[attr = "val"]
31     pub fn f() { }
32
33     #[attr = "val"]
34     pub mod mod1 {}
35
36     pub mod rustrt {
37         #[attr = "val"]
38         extern {}
39     }
40 }
41
42 mod test_multi_attr_outer {
43     #[attr1 = "val"]
44     #[attr2 = "val"]
45     pub static x: int = 10;
46
47     #[attr1 = "val"]
48     #[attr2 = "val"]
49     pub fn f() { }
50
51     #[attr1 = "val"]
52     #[attr2 = "val"]
53     pub mod mod1 {}
54
55     pub mod rustrt {
56         #[attr1 = "val"]
57         #[attr2 = "val"]
58         extern {}
59     }
60
61     #[attr1 = "val"]
62     #[attr2 = "val"]
63     struct t {x: int}
64 }
65
66 mod test_stmt_single_attr_outer {
67     pub fn f() {
68         #[attr = "val"]
69         static x: int = 10;
70
71         #[attr = "val"]
72         fn f() { }
73
74         #[attr = "val"]
75         mod mod1 {
76         }
77
78         mod rustrt {
79             #[attr = "val"]
80             extern {
81             }
82         }
83     }
84 }
85
86 mod test_stmt_multi_attr_outer {
87     pub fn f() {
88
89         #[attr1 = "val"]
90         #[attr2 = "val"]
91         static x: int = 10;
92
93         #[attr1 = "val"]
94         #[attr2 = "val"]
95         fn f() { }
96
97         /* FIXME: Issue #493
98         #[attr1 = "val"]
99         #[attr2 = "val"]
100         mod mod1 {
101         }
102
103         pub mod rustrt {
104             #[attr1 = "val"]
105             #[attr2 = "val"]
106             extern {
107             }
108         }
109         */
110     }
111 }
112
113 mod test_attr_inner {
114     pub mod m {
115         // This is an attribute of mod m
116         #![attr = "val"]
117     }
118 }
119
120 mod test_attr_inner_then_outer {
121     pub mod m {
122         // This is an attribute of mod m
123         #![attr = "val"]
124         // This is an attribute of fn f
125         #[attr = "val"]
126         fn f() { }
127     }
128 }
129
130 mod test_attr_inner_then_outer_multi {
131     pub mod m {
132         // This is an attribute of mod m
133         #![attr1 = "val"]
134         #![attr2 = "val"]
135         // This is an attribute of fn f
136         #[attr1 = "val"]
137         #[attr2 = "val"]
138         fn f() { }
139     }
140 }
141
142 mod test_distinguish_syntax_ext {
143     pub fn f() {
144         format!("test{}", "s");
145         #[attr = "val"]
146         fn g() { }
147     }
148 }
149
150 mod test_other_forms {
151     #[attr]
152     #[attr(word)]
153     #[attr(attr(word))]
154     #[attr(key1 = "val", key2 = "val", attr)]
155     pub fn f() { }
156 }
157
158 mod test_foreign_items {
159     pub mod rustrt {
160         extern crate libc;
161
162         extern {
163             #![attr]
164
165             #[attr]
166             fn rust_get_test_int() -> libc::intptr_t;
167         }
168     }
169 }
170
171
172 // FIXME #623 - these aren't supported yet
173 /*mod test_literals {
174     #![str = "s"]
175     #![char = 'c']
176     #![int = 100]
177     #![uint = 100u]
178     #![mach_int = 100u32]
179     #![float = 1.0]
180     #![mach_float = 1.0f32]
181     #![nil = ()]
182     #![bool = true]
183     mod m {}
184 }*/
185
186 fn test_fn_inner() {
187     #![inner_fn_attr]
188 }
189
190 pub fn main() { }