]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/doc_unsafe.rs
Merge commit 'c19edfd71a1d0ddef86c2c67fdb40718d40a72b4' into sync_cg_clif-2022-07-25
[rust.git] / src / tools / clippy / tests / ui / doc_unsafe.rs
1 // aux-build:doc_unsafe_macros.rs
2
3 #![allow(clippy::let_unit_value)]
4
5 #[macro_use]
6 extern crate doc_unsafe_macros;
7
8 /// This is not sufficiently documented
9 pub unsafe fn destroy_the_planet() {
10     unimplemented!();
11 }
12
13 /// This one is
14 ///
15 /// # Safety
16 ///
17 /// This function shouldn't be called unless the horsemen are ready
18 pub unsafe fn apocalypse(universe: &mut ()) {
19     unimplemented!();
20 }
21
22 /// This is a private function, so docs aren't necessary
23 unsafe fn you_dont_see_me() {
24     unimplemented!();
25 }
26
27 mod private_mod {
28     pub unsafe fn only_crate_wide_accessible() {
29         unimplemented!();
30     }
31
32     pub unsafe fn republished() {
33         unimplemented!();
34     }
35 }
36
37 pub use private_mod::republished;
38
39 pub trait SafeTraitUnsafeMethods {
40     unsafe fn woefully_underdocumented(self);
41
42     /// # Safety
43     unsafe fn at_least_somewhat_documented(self);
44 }
45
46 pub unsafe trait UnsafeTrait {
47     fn method();
48 }
49
50 /// # Safety
51 pub unsafe trait DocumentedUnsafeTrait {
52     fn method2();
53 }
54
55 pub struct Struct;
56
57 impl SafeTraitUnsafeMethods for Struct {
58     unsafe fn woefully_underdocumented(self) {
59         // all is well
60     }
61
62     unsafe fn at_least_somewhat_documented(self) {
63         // all is still well
64     }
65 }
66
67 unsafe impl UnsafeTrait for Struct {
68     fn method() {}
69 }
70
71 unsafe impl DocumentedUnsafeTrait for Struct {
72     fn method2() {}
73 }
74
75 impl Struct {
76     pub unsafe fn more_undocumented_unsafe() -> Self {
77         unimplemented!();
78     }
79
80     /// # Safety
81     pub unsafe fn somewhat_documented(&self) {
82         unimplemented!();
83     }
84
85     unsafe fn private(&self) {
86         unimplemented!();
87     }
88 }
89
90 macro_rules! very_unsafe {
91     () => {
92         pub unsafe fn whee() {
93             unimplemented!()
94         }
95
96         /// # Safety
97         ///
98         /// Please keep the seat belt fastened
99         pub unsafe fn drive() {
100             whee()
101         }
102     };
103 }
104
105 very_unsafe!();
106
107 // we don't lint code from external macros
108 undocd_unsafe!();
109
110 fn main() {
111     unsafe {
112         you_dont_see_me();
113         destroy_the_planet();
114         let mut universe = ();
115         apocalypse(&mut universe);
116         private_mod::only_crate_wide_accessible();
117         drive();
118     }
119 }
120
121 // do not lint if any parent has `#[doc(hidden)]` attribute
122 // see #7347
123 #[doc(hidden)]
124 pub mod __macro {
125     pub struct T;
126     impl T {
127         pub unsafe fn f() {}
128     }
129 }
130
131 /// # Implementation safety
132 pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader {
133     fn method();
134 }