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