]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
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 | ||
c295e0f8 | 37 | pub trait SafeTraitUnsafeMethods { |
f20569fa XL |
38 | unsafe fn woefully_underdocumented(self); |
39 | ||
40 | /// # Safety | |
41 | unsafe fn at_least_somewhat_documented(self); | |
42 | } | |
43 | ||
c295e0f8 XL |
44 | pub unsafe trait UnsafeTrait { |
45 | fn method(); | |
46 | } | |
47 | ||
48 | /// # Safety | |
49 | pub unsafe trait DocumentedUnsafeTrait { | |
50 | fn method2(); | |
51 | } | |
52 | ||
f20569fa XL |
53 | pub struct Struct; |
54 | ||
c295e0f8 | 55 | impl SafeTraitUnsafeMethods for Struct { |
f20569fa XL |
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 | ||
c295e0f8 XL |
65 | unsafe impl UnsafeTrait for Struct { |
66 | fn method() {} | |
67 | } | |
68 | ||
69 | unsafe impl DocumentedUnsafeTrait for Struct { | |
70 | fn method2() {} | |
71 | } | |
72 | ||
f20569fa XL |
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 | } |