]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/doc_unsafe.rs
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
[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 SafeTraitUnsafeMethods {
38     unsafe fn woefully_underdocumented(self);
39
40     /// # Safety
41     unsafe fn at_least_somewhat_documented(self);
42 }
43
44 pub unsafe trait UnsafeTrait {
45     fn method();
46 }
47
48 /// # Safety
49 pub unsafe trait DocumentedUnsafeTrait {
50     fn method2();
51 }
52
53 pub struct Struct;
54
55 impl SafeTraitUnsafeMethods for Struct {
56     unsafe fn woefully_underdocumented(self) {
57         // all is well
58     }
59
60     unsafe fn at_least_somewhat_documented(self) {
61         // all is still well
62     }
63 }
64
65 unsafe impl UnsafeTrait for Struct {
66     fn method() {}
67 }
68
69 unsafe impl DocumentedUnsafeTrait for Struct {
70     fn method2() {}
71 }
72
73 impl Struct {
74     pub unsafe fn more_undocumented_unsafe() -> Self {
75         unimplemented!();
76     }
77
78     /// # Safety
79     pub unsafe fn somewhat_documented(&self) {
80         unimplemented!();
81     }
82
83     unsafe fn private(&self) {
84         unimplemented!();
85     }
86 }
87
88 macro_rules! very_unsafe {
89     () => {
90         pub unsafe fn whee() {
91             unimplemented!()
92         }
93
94         /// # Safety
95         ///
96         /// Please keep the seat belt fastened
97         pub unsafe fn drive() {
98             whee()
99         }
100     };
101 }
102
103 very_unsafe!();
104
105 // we don't lint code from external macros
106 undocd_unsafe!();
107
108 fn main() {
109     unsafe {
110         you_dont_see_me();
111         destroy_the_planet();
112         let mut universe = ();
113         apocalypse(&mut universe);
114         private_mod::only_crate_wide_accessible();
115         drive();
116     }
117 }
118
119 // do not lint if any parent has `#[doc(hidden)]` attribute
120 // see #7347
121 #[doc(hidden)]
122 pub mod __macro {
123     pub struct T;
124     impl T {
125         pub unsafe fn f() {}
126     }
127 }