]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/item-attributes.rs
Imported Upstream version 0.7
[rustc.git] / src / test / run-pass / item-attributes.rs
CommitLineData
223e47cc
LB
1// Copyright 2012 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// Special linkage attributes for the crate
970d7e83 20#[link(name = "extra",
223e47cc
LB
21 vers = "0.1",
22 uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
970d7e83 23 url = "http://rust-lang.org/src/extra")];
223e47cc 24
970d7e83 25// These are attributes of the following mod
223e47cc
LB
26#[attr1 = "val"]
27#[attr2 = "val"]
28mod test_first_item_in_file_mod {}
29
30mod test_single_attr_outer {
31 #[attr = "val"]
32 pub static x: int = 10;
33
34 #[attr = "val"]
35 pub fn f() { }
36
37 #[attr = "val"]
38 pub mod mod1 {}
39
40 pub mod rustrt {
41 #[attr = "val"]
42 #[abi = "cdecl"]
43 pub extern {}
44 }
45}
46
47mod test_multi_attr_outer {
48 #[attr1 = "val"]
49 #[attr2 = "val"]
50 pub static x: int = 10;
51
52 #[attr1 = "val"]
53 #[attr2 = "val"]
54 pub fn f() { }
55
56 #[attr1 = "val"]
57 #[attr2 = "val"]
58 pub mod mod1 {}
59
60 pub mod rustrt {
61 #[attr1 = "val"]
62 #[attr2 = "val"]
63 #[abi = "cdecl"]
64 pub extern {}
65 }
66
67 #[attr1 = "val"]
68 #[attr2 = "val"]
69 struct t {x: int}
70}
71
72mod test_stmt_single_attr_outer {
73 pub fn f() {
74 #[attr = "val"]
75 static x: int = 10;
76
77 #[attr = "val"]
78 fn f() { }
79
80 #[attr = "val"]
81 mod mod1 {
82 }
83
84 mod rustrt {
85 #[attr = "val"]
86 #[abi = "cdecl"]
87 pub extern {
88 }
89 }
90 }
91}
92
93mod test_stmt_multi_attr_outer {
94 pub fn f() {
95
96 #[attr1 = "val"]
97 #[attr2 = "val"]
98 static x: int = 10;
99
100 #[attr1 = "val"]
101 #[attr2 = "val"]
102 fn f() { }
103
104 /* FIXME: Issue #493
105 #[attr1 = "val"]
106 #[attr2 = "val"]
107 mod mod1 {
108 }
109
110 pub mod rustrt {
111 #[attr1 = "val"]
112 #[attr2 = "val"]
113 #[abi = "cdecl"]
114 pub extern {
115 }
116 }
117 */
118 }
119}
120
121mod test_attr_inner {
122 pub mod m {
123 // This is an attribute of mod m
124 #[attr = "val"];
125 }
126}
127
128mod test_attr_inner_then_outer {
129 pub mod m {
130 // This is an attribute of mod m
131 #[attr = "val"];
132 // This is an attribute of fn f
133 #[attr = "val"]
134 fn f() { }
135 }
136}
137
138mod test_attr_inner_then_outer_multi {
139 pub mod m {
140 // This is an attribute of mod m
141 #[attr1 = "val"];
142 #[attr2 = "val"];
143 // This is an attribute of fn f
144 #[attr1 = "val"]
145 #[attr2 = "val"]
146 fn f() { }
147 }
148}
149
150mod test_distinguish_syntax_ext {
970d7e83 151 extern mod extra;
223e47cc
LB
152
153 pub fn f() {
154 fmt!("test%s", ~"s");
155 #[attr = "val"]
156 fn g() { }
157 }
158}
159
160mod test_other_forms {
161 #[attr]
162 #[attr(word)]
163 #[attr(attr(word))]
164 #[attr(key1 = "val", key2 = "val", attr)]
165 pub fn f() { }
166}
167
168mod test_foreign_items {
169 pub mod rustrt {
970d7e83
LB
170 use std::libc;
171
223e47cc
LB
172 #[abi = "cdecl"]
173 pub extern {
174 #[attr];
175
176 #[attr]
177 fn get_task_id() -> libc::intptr_t;
178 }
179 }
180}
181
182mod test_literals {
183 #[str = "s"];
184 #[char = 'c'];
185 #[int = 100];
186 #[uint = 100u];
187 #[mach_int = 100u32];
188 #[float = 1.0];
189 #[mach_float = 1.0f32];
190 #[nil = ()];
191 #[bool = true];
192 mod m {}
193}
194
195fn test_fn_inner() {
196 #[inner_fn_attr];
197}
198
199pub fn main() { }