]> git.lizzy.rs Git - rust.git/blob - tests/source/attrib.rs
Merge pull request #2971 from topecongiro/issue-2969
[rust.git] / tests / source / attrib.rs
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.
27 impl Bar {
28     /// Blah blah blooo.
29     /// Blah blah blooo.
30     /// Blah blah blooo.
31     /// Blah blah blooo.
32     #[an_attribute]
33     fn foo(&mut self) -> isize {
34     }
35
36     /// Blah blah bing.
37     /// Blah blah bing.
38     /// Blah blah bing.
39
40
41     /// Blah blah bing.
42     /// Blah blah bing.
43     /// Blah blah bing.
44     pub fn f2(self) {
45         (foo, bar)
46     }
47
48     #[another_attribute]
49     fn f3(self) -> Dog {
50     }
51
52     /// Blah blah bing.
53
54     #[attrib1]
55     /// Blah blah bing.
56     #[attrib2]
57     // Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo loooooooooooong.
58     /// Blah blah bing.
59     fn f4(self) -> Cat {
60     }
61
62     // We want spaces around `=`
63     #[cfg(feature="nightly")]
64     fn f5(self) -> Monkey {}
65 }
66
67 // #984
68 struct Foo {
69     # [ derive ( Clone , PartialEq , Debug , Deserialize , Serialize ) ]
70     foo: usize,
71 }
72
73 // #1668
74
75 /// Default path (*nix)
76 #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
77 fn foo() {
78     #[cfg(target_os = "freertos")]
79     match port_id {
80         'a' | 'A' => GpioPort { port_address: GPIO_A },
81         'b' | 'B' => GpioPort { port_address: GPIO_B },
82         _ => panic!(),
83     }
84
85     #[cfg_attr(not(target_os = "freertos"), allow(unused_variables))]
86     let x = 3;
87 }
88
89 // #1777
90 #[test]
91 #[should_panic(expected = "(")]
92 #[should_panic(expected = /* ( */ "(")]
93 #[should_panic(/* ((((( */expected /* ((((( */= /* ((((( */ "("/* ((((( */)]
94 #[should_panic(
95     /* (((((((( *//*
96     (((((((((()(((((((( */
97     expected = "("
98     // ((((((((
99 )]
100 fn foo() {}
101
102 // #1799
103 fn issue_1799() {
104     #[allow(unreachable_code)] // https://github.com/rust-lang/rust/issues/43336
105     Some( Err(error) ) ;
106
107     #[allow(unreachable_code)]
108     // https://github.com/rust-lang/rust/issues/43336
109     Some( Err(error) ) ;
110 }
111
112 // Formatting inner attributes
113 fn inner_attributes() {
114     #![ this_is_an_inner_attribute ( foo ) ]
115
116     foo();
117 }
118
119 impl InnerAttributes() {
120     #![ this_is_an_inner_attribute ( foo ) ]
121
122     fn foo() {}
123 }
124
125 mod InnerAttributes {
126     #![ this_is_an_inner_attribute ( foo ) ]
127 }
128
129 fn attributes_on_statements() {
130     // Local
131     # [ attr ( on ( local ) ) ]
132     let x = 3;
133
134     // Item
135     # [ attr ( on ( item ) ) ]
136     use foo;
137
138     // Expr
139     # [ attr ( on ( expr ) ) ]
140     {}
141
142     // Semi
143     # [ attr ( on ( semi ) ) ]
144     foo();
145
146     // Mac
147     # [ attr ( on ( mac ) ) ]
148     foo!();
149 }
150
151 // Large derives
152 #[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Mul)]
153
154
155 /// Foo bar baz
156
157
158 #[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Deserialize)]
159 pub struct HP(pub u8);
160
161 // Long `#[doc = "..."]`
162 struct A { #[doc = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] b: i32 }
163
164 // #2647
165 #[cfg(feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")]
166 pub fn foo() {}
167
168 // path attrs
169 #[clippy::bar]
170 #[clippy::bar=foo]
171 #[clippy::bar(a, b, c)]
172 pub fn foo() {}
173
174 mod issue_2620 {
175     #[derive(Debug, StructOpt)]
176 #[structopt(about = "Display information about the character on FF Logs")]
177 pub 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", target_os = "bitrig",
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               ))))]
212 type Os = NoSource;