]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // rustfmt-wrap_comments: true |
2 | // Test attributes and doc comments are preserved. | |
3 | #![doc( | |
4 | html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", | |
5 | html_favicon_url = "https://doc.rust-lang.org/favicon.ico", | |
6 | html_root_url = "https://doc.rust-lang.org/nightly/", | |
7 | html_playground_url = "https://play.rust-lang.org/", | |
8 | test(attr(deny(warnings))) | |
9 | )] | |
10 | ||
11 | //! Doc comment | |
12 | ||
13 | #![attribute] | |
14 | ||
15 | //! Crate doc comment | |
16 | ||
17 | // Comment | |
18 | ||
19 | // Comment on attribute | |
20 | #![the(attribute)] | |
21 | ||
22 | // Another comment | |
23 | ||
24 | /// Blah blah blah. | |
25 | /// Blah blah blah. | |
26 | /// Blah blah blah. | |
27 | /// Blah blah blah. | |
28 | ||
29 | /// Blah blah blah. | |
30 | impl Bar { | |
31 | /// Blah blah blooo. | |
32 | /// Blah blah blooo. | |
33 | /// Blah blah blooo. | |
34 | /// Blah blah blooo. | |
35 | #[an_attribute] | |
36 | #[doc = "an attribute that shouldn't be normalized to a doc comment"] | |
37 | fn foo(&mut self) -> isize {} | |
38 | ||
39 | /// Blah blah bing. | |
40 | /// Blah blah bing. | |
41 | /// Blah blah bing. | |
42 | ||
43 | /// Blah blah bing. | |
44 | /// Blah blah bing. | |
45 | /// Blah blah bing. | |
46 | pub fn f2(self) { | |
47 | (foo, bar) | |
48 | } | |
49 | ||
50 | #[another_attribute] | |
51 | fn f3(self) -> Dog {} | |
52 | ||
53 | /// Blah blah bing. | |
54 | ||
55 | #[attrib1] | |
56 | /// Blah blah bing. | |
57 | #[attrib2] | |
58 | // Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo | |
59 | // loooooooooooong. | |
60 | /// Blah blah bing. | |
61 | fn f4(self) -> Cat {} | |
62 | ||
63 | // We want spaces around `=` | |
64 | #[cfg(feature = "nightly")] | |
65 | fn f5(self) -> Monkey {} | |
66 | } | |
67 | ||
68 | // #984 | |
69 | struct Foo { | |
70 | #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] | |
71 | foo: usize, | |
72 | } | |
73 | ||
74 | // #1668 | |
75 | ||
76 | /// Default path (*nix) | |
77 | #[cfg(all( | |
78 | unix, | |
79 | not(target_os = "macos"), | |
80 | not(target_os = "ios"), | |
81 | not(target_os = "android") | |
82 | ))] | |
83 | fn foo() { | |
84 | #[cfg(target_os = "freertos")] | |
85 | match port_id { | |
86 | 'a' | 'A' => GpioPort { | |
87 | port_address: GPIO_A, | |
88 | }, | |
89 | 'b' | 'B' => GpioPort { | |
90 | port_address: GPIO_B, | |
91 | }, | |
92 | _ => panic!(), | |
93 | } | |
94 | ||
95 | #[cfg_attr(not(target_os = "freertos"), allow(unused_variables))] | |
96 | let x = 3; | |
97 | } | |
98 | ||
99 | // #1777 | |
100 | #[test] | |
101 | #[should_panic(expected = "(")] | |
102 | #[should_panic(expected = /* ( */ "(")] | |
103 | #[should_panic(/* ((((( */expected /* ((((( */= /* ((((( */ "("/* ((((( */)] | |
104 | #[should_panic( | |
105 | /* (((((((( *//* | |
106 | (((((((((()(((((((( */ | |
107 | expected = "(" | |
108 | // (((((((( | |
109 | )] | |
110 | fn foo() {} | |
111 | ||
112 | // #1799 | |
113 | fn issue_1799() { | |
114 | #[allow(unreachable_code)] // https://github.com/rust-lang/rust/issues/43336 | |
115 | Some(Err(error)); | |
116 | ||
117 | #[allow(unreachable_code)] | |
118 | // https://github.com/rust-lang/rust/issues/43336 | |
119 | Some(Err(error)); | |
120 | } | |
121 | ||
122 | // Formatting inner attributes | |
123 | fn inner_attributes() { | |
124 | #![this_is_an_inner_attribute(foo)] | |
125 | ||
126 | foo(); | |
127 | } | |
128 | ||
129 | impl InnerAttributes() { | |
130 | #![this_is_an_inner_attribute(foo)] | |
131 | ||
132 | fn foo() {} | |
133 | } | |
134 | ||
135 | mod InnerAttributes { | |
136 | #![this_is_an_inner_attribute(foo)] | |
137 | } | |
138 | ||
139 | fn attributes_on_statements() { | |
140 | // Local | |
141 | #[attr(on(local))] | |
142 | let x = 3; | |
143 | ||
144 | // Item | |
145 | #[attr(on(item))] | |
146 | use foo; | |
147 | ||
148 | // Expr | |
149 | #[attr(on(expr))] | |
150 | {} | |
151 | ||
152 | // Semi | |
153 | #[attr(on(semi))] | |
154 | foo(); | |
155 | ||
156 | // Mac | |
157 | #[attr(on(mac))] | |
158 | foo!(); | |
159 | } | |
160 | ||
161 | // Large derives | |
162 | #[derive( | |
163 | Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Mul, | |
164 | )] | |
165 | ||
166 | /// Foo bar baz | |
167 | ||
168 | #[derive( | |
169 | Add, | |
170 | Sub, | |
171 | Mul, | |
172 | Div, | |
173 | Clone, | |
174 | Copy, | |
175 | Eq, | |
176 | PartialEq, | |
177 | Ord, | |
178 | PartialOrd, | |
179 | Debug, | |
180 | Hash, | |
181 | Serialize, | |
182 | Deserialize, | |
183 | )] | |
184 | pub struct HP(pub u8); | |
185 | ||
186 | // Long `#[doc = "..."]` | |
187 | struct A { | |
188 | #[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] | |
189 | b: i32, | |
190 | } | |
191 | ||
192 | // #2647 | |
193 | #[cfg( | |
194 | feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
195 | )] | |
196 | pub fn foo() {} | |
197 | ||
198 | // path attrs | |
199 | #[clippy::bar] | |
200 | #[clippy::bar(a, b, c)] | |
201 | pub fn foo() {} | |
202 | ||
203 | mod issue_2620 { | |
204 | #[derive(Debug, StructOpt)] | |
205 | #[structopt(about = "Display information about the character on FF Logs")] | |
206 | pub struct Params { | |
207 | #[structopt(help = "The server the character is on")] | |
208 | server: String, | |
209 | #[structopt(help = "The character's first name")] | |
210 | first_name: String, | |
211 | #[structopt(help = "The character's last name")] | |
212 | last_name: String, | |
213 | #[structopt( | |
214 | short = "j", | |
215 | long = "job", | |
216 | help = "The job to look at", | |
217 | parse(try_from_str) | |
218 | )] | |
219 | job: Option<Job>, | |
220 | } | |
221 | } | |
222 | ||
223 | // #2969 | |
224 | #[cfg(not(all( | |
225 | feature = "std", | |
226 | any( | |
227 | target_os = "linux", | |
228 | target_os = "android", | |
229 | target_os = "netbsd", | |
230 | target_os = "dragonfly", | |
231 | target_os = "haiku", | |
232 | target_os = "emscripten", | |
233 | target_os = "solaris", | |
234 | target_os = "cloudabi", | |
235 | target_os = "macos", | |
236 | target_os = "ios", | |
237 | target_os = "freebsd", | |
238 | target_os = "openbsd", | |
239 | target_os = "redox", | |
240 | target_os = "fuchsia", | |
241 | windows, | |
242 | all(target_arch = "wasm32", feature = "stdweb"), | |
243 | all(target_arch = "wasm32", feature = "wasm-bindgen"), | |
244 | ) | |
245 | )))] | |
246 | type Os = NoSource; | |
247 | ||
248 | // #3313 | |
249 | fn stmt_expr_attributes() { | |
250 | let foo; | |
251 | #[must_use] | |
252 | foo = false; | |
253 | } | |
254 | ||
255 | // #3509 | |
256 | fn issue3509() { | |
257 | match MyEnum { | |
258 | MyEnum::Option1 if cfg!(target_os = "windows") => | |
259 | #[cfg(target_os = "windows")] | |
260 | { | |
261 | 1 | |
262 | } | |
263 | } | |
264 | match MyEnum { | |
265 | MyEnum::Option1 if cfg!(target_os = "windows") => | |
266 | { | |
267 | #[cfg(target_os = "windows")] | |
268 | 1 | |
269 | } | |
270 | } | |
271 | } |