]> git.lizzy.rs Git - rust.git/blob - tests/source/attrib.rs
Merge pull request #1888 from topecongiro/no-panic-against-invalid-attr
[rust.git] / tests / source / attrib.rs
1 // rustfmt-wrap_comments: true
2 // Test attributes and doc comments are preserved.
3
4 #[invalid attribute]
5 fn foo() {}
6
7 /// Blah blah blah.
8 /// Blah blah blah.
9 /// Blah blah blah.
10 /// Blah blah blah.
11
12 /// Blah blah blah.
13 impl Bar {
14     /// Blah blah blooo.
15     /// Blah blah blooo.
16     /// Blah blah blooo.
17     /// Blah blah blooo.
18     #[an_attribute]
19     fn foo(&mut self) -> isize {
20     }
21
22     /// Blah blah bing.
23     /// Blah blah bing.
24     /// Blah blah bing.
25
26
27     /// Blah blah bing.
28     /// Blah blah bing.
29     /// Blah blah bing.
30     pub fn f2(self) {
31         (foo, bar)
32     }
33
34     #[another_attribute]
35     fn f3(self) -> Dog {
36     }
37
38     /// Blah blah bing.
39
40     #[attrib1]
41     /// Blah blah bing.
42     #[attrib2]
43     // Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo loooooooooooong.
44     /// Blah blah bing.
45     fn f4(self) -> Cat {
46     }
47
48     // We want spaces around `=`
49     #[cfg(feature="nightly")]
50     fn f5(self) -> Monkey {}
51 }
52
53 // #984
54 struct Foo {
55     # [ derive ( Clone , PartialEq , Debug , Deserialize , Serialize ) ]
56     foo: usize,
57 }
58
59 // #1668
60
61 /// Default path (*nix)
62 #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
63 fn foo() {
64     #[cfg(target_os = "freertos")]
65     match port_id {
66         'a' | 'A' => GpioPort { port_address: GPIO_A },
67         'b' | 'B' => GpioPort { port_address: GPIO_B },
68         _ => panic!(),
69     }
70
71     #[cfg_attr(not(target_os = "freertos"), allow(unused_variables))]
72     let x = 3;
73 }
74
75 // #1777
76 #[test]
77 #[should_panic(expected = "(")]
78 #[should_panic(expected = /* ( */ "(")]
79 #[should_panic(/* ((((( */expected /* ((((( */= /* ((((( */ "("/* ((((( */)]
80 #[should_panic(
81     /* (((((((( *//*
82     (((((((((()(((((((( */
83     expected = "("
84     // ((((((((
85 )]
86 fn foo() {}
87
88 // #1799
89 fn issue_1799() {
90     #[allow(unreachable_code)] // https://github.com/rust-lang/rust/issues/43336
91     Some( Err(error) ) ;
92
93     #[allow(unreachable_code)]
94     // https://github.com/rust-lang/rust/issues/43336
95     Some( Err(error) ) ;
96 }
97
98 // Formatting inner attributes
99 fn inner_attributes() {
100     #![ this_is_an_inner_attribute ( foo ) ]
101
102     foo();
103 }
104
105 impl InnerAttributes() {
106     #![ this_is_an_inner_attribute ( foo ) ]
107
108     fn foo() {}
109 }
110
111 mod InnerAttributes {
112     #![ this_is_an_inner_attribute ( foo ) ]
113 }