]> git.lizzy.rs Git - rust.git/blob - tests/target/attrib.rs
Merge pull request #1933 from topecongiro/attributes-on-stmt
[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)] foo: usize,
66 }
67
68 // #1668
69
70 /// Default path (*nix)
71 #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
72 fn foo() {
73     #[cfg(target_os = "freertos")]
74     match port_id {
75         'a' | 'A' => GpioPort {
76             port_address: GPIO_A,
77         },
78         'b' | 'B' => GpioPort {
79             port_address: GPIO_B,
80         },
81         _ => panic!(),
82     }
83
84     #[cfg_attr(not(target_os = "freertos"), allow(unused_variables))]
85     let x = 3;
86 }
87
88 // #1777
89 #[test]
90 #[should_panic(expected = "(")]
91 #[should_panic(expected = /* ( */ "(")]
92 #[should_panic(/* ((((( */expected /* ((((( */= /* ((((( */ "("/* ((((( */)]
93 #[should_panic(
94     /* (((((((( *//*
95     (((((((((()(((((((( */
96     expected = "("
97     // ((((((((
98 )]
99 fn foo() {}
100
101 // #1799
102 fn issue_1799() {
103     #[allow(unreachable_code)] // https://github.com/rust-lang/rust/issues/43336
104     Some(Err(error));
105
106     #[allow(unreachable_code)]
107     // https://github.com/rust-lang/rust/issues/43336
108     Some(Err(error));
109 }
110
111 // Formatting inner attributes
112 fn inner_attributes() {
113     #![this_is_an_inner_attribute(foo)]
114
115     foo();
116 }
117
118 impl InnerAttributes() {
119     #![this_is_an_inner_attribute(foo)]
120
121     fn foo() {}
122 }
123
124 mod InnerAttributes {
125     #![this_is_an_inner_attribute(foo)]
126 }
127
128 fn attributes_on_statements() {
129     // Local
130     #[attr(on(local))]
131     let x = 3;
132
133     // Item
134     #[attr(on(item))]
135     use foo;
136
137     // Expr
138     #[attr(on(expr))]
139     {}
140
141     // Semi
142     #[attr(on(semi))]
143     foo();
144
145     // Mac
146     #[attr(on(mac))]
147     foo!();
148 }