]> git.lizzy.rs Git - rust.git/blob - tests/target/attrib.rs
Merge pull request #2357 from topecongiro/issue-2342
[rust.git] / tests / target / attrib.rs
1 // rustfmt-wrap_comments: true
2 // Test attributes and doc comments are preserved.
3
4 //! Doc comment
5
6 #![attribute]
7
8 //! Crate doc comment
9
10 // Comment
11
12 // Comment on attribute
13 #![the(attribute)]
14
15 // Another comment
16
17 #[invalid attribute]
18 fn foo() {}
19
20 /// Blah blah blah.
21 /// Blah blah blah.
22 /// Blah blah blah.
23 /// Blah blah blah.
24
25 /// Blah blah blah.
26 impl Bar {
27     /// Blah blah blooo.
28     /// Blah blah blooo.
29     /// Blah blah blooo.
30     /// Blah blah blooo.
31     #[an_attribute]
32     fn foo(&mut self) -> isize {}
33
34     /// Blah blah bing.
35     /// Blah blah bing.
36     /// Blah blah bing.
37
38     /// Blah blah bing.
39     /// Blah blah bing.
40     /// Blah blah bing.
41     pub fn f2(self) {
42         (foo, bar)
43     }
44
45     #[another_attribute]
46     fn f3(self) -> Dog {}
47
48     /// Blah blah bing.
49
50     #[attrib1]
51     /// Blah blah bing.
52     #[attrib2]
53     // Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo
54     // loooooooooooong.
55     /// Blah blah bing.
56     fn f4(self) -> Cat {}
57
58     // We want spaces around `=`
59     #[cfg(feature = "nightly")]
60     fn f5(self) -> Monkey {}
61 }
62
63 // #984
64 struct Foo {
65     #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
66     foo: usize,
67 }
68
69 // #1668
70
71 /// Default path (*nix)
72 #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
73 fn foo() {
74     #[cfg(target_os = "freertos")]
75     match port_id {
76         'a' | 'A' => GpioPort {
77             port_address: GPIO_A,
78         },
79         'b' | 'B' => GpioPort {
80             port_address: GPIO_B,
81         },
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 derive
152 #[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize,
153          Deserialize)]
154 pub struct HP(pub u8);