]> git.lizzy.rs Git - rust.git/blob - tests/source/attrib.rs
Merge pull request #1942 from topecongiro/fixes
[rust.git] / tests / source / 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
35     /// Blah blah bing.
36     /// Blah blah bing.
37     /// Blah blah bing.
38
39
40     /// Blah blah bing.
41     /// Blah blah bing.
42     /// Blah blah bing.
43     pub fn f2(self) {
44         (foo, bar)
45     }
46
47     #[another_attribute]
48     fn f3(self) -> Dog {
49     }
50
51     /// Blah blah bing.
52
53     #[attrib1]
54     /// Blah blah bing.
55     #[attrib2]
56     // Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo loooooooooooong.
57     /// Blah blah bing.
58     fn f4(self) -> Cat {
59     }
60
61     // We want spaces around `=`
62     #[cfg(feature="nightly")]
63     fn f5(self) -> Monkey {}
64 }
65
66 // #984
67 struct Foo {
68     # [ derive ( Clone , PartialEq , Debug , Deserialize , Serialize ) ]
69     foo: usize,
70 }
71
72 // #1668
73
74 /// Default path (*nix)
75 #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
76 fn foo() {
77     #[cfg(target_os = "freertos")]
78     match port_id {
79         'a' | 'A' => GpioPort { port_address: GPIO_A },
80         'b' | 'B' => GpioPort { port_address: GPIO_B },
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 }
149
150 // Large derive
151 #[derive(Add, Sub, Mul, Div, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Serialize, Deserialize)]
152 pub struct HP(pub u8);