]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/doc_unsafe.rs
Rollup merge of #78769 - est31:remove_lifetimes, r=KodrAus
[rust.git] / src / tools / clippy / tests / ui / doc_unsafe.rs
1 // aux-build:doc_unsafe_macros.rs
2
3 #[macro_use]
4 extern crate doc_unsafe_macros;
5
6 /// This is not sufficiently documented
7 pub unsafe fn destroy_the_planet() {
8     unimplemented!();
9 }
10
11 /// This one is
12 ///
13 /// # Safety
14 ///
15 /// This function shouldn't be called unless the horsemen are ready
16 pub unsafe fn apocalypse(universe: &mut ()) {
17     unimplemented!();
18 }
19
20 /// This is a private function, so docs aren't necessary
21 unsafe fn you_dont_see_me() {
22     unimplemented!();
23 }
24
25 mod private_mod {
26     pub unsafe fn only_crate_wide_accessible() {
27         unimplemented!();
28     }
29
30     pub unsafe fn republished() {
31         unimplemented!();
32     }
33 }
34
35 pub use private_mod::republished;
36
37 pub trait UnsafeTrait {
38     unsafe fn woefully_underdocumented(self);
39
40     /// # Safety
41     unsafe fn at_least_somewhat_documented(self);
42 }
43
44 pub struct Struct;
45
46 impl UnsafeTrait for Struct {
47     unsafe fn woefully_underdocumented(self) {
48         // all is well
49     }
50
51     unsafe fn at_least_somewhat_documented(self) {
52         // all is still well
53     }
54 }
55
56 impl Struct {
57     pub unsafe fn more_undocumented_unsafe() -> Self {
58         unimplemented!();
59     }
60
61     /// # Safety
62     pub unsafe fn somewhat_documented(&self) {
63         unimplemented!();
64     }
65
66     unsafe fn private(&self) {
67         unimplemented!();
68     }
69 }
70
71 macro_rules! very_unsafe {
72     () => {
73         pub unsafe fn whee() {
74             unimplemented!()
75         }
76
77         /// # Safety
78         ///
79         /// Please keep the seat belt fastened
80         pub unsafe fn drive() {
81             whee()
82         }
83     };
84 }
85
86 very_unsafe!();
87
88 // we don't lint code from external macros
89 undocd_unsafe!();
90
91 fn main() {
92     unsafe {
93         you_dont_see_me();
94         destroy_the_planet();
95         let mut universe = ();
96         apocalypse(&mut universe);
97         private_mod::only_crate_wide_accessible();
98         drive();
99     }
100 }