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