1 // aux-build:doc_unsafe_macros.rs 2 3 #[macro_use] 4 extern crate doc_unsafe_macros; 5 6 /// This is not sufficiently documented destroy_the_planet()7pub 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 apocalypse(universe: &mut ())16pub unsafe fn apocalypse(universe: &mut ()) { 17 unimplemented!(); 18 } 19 20 /// This is a private function, so docs aren't necessary you_dont_see_me()21unsafe fn you_dont_see_me() { 22 unimplemented!(); 23 } 24 25 mod private_mod { only_crate_wide_accessible()26 pub unsafe fn only_crate_wide_accessible() { 27 unimplemented!(); 28 } 29 republished()30 pub unsafe fn republished() { 31 unimplemented!(); 32 } 33 } 34 35 pub use private_mod::republished; 36 37 pub trait SafeTraitUnsafeMethods { woefully_underdocumented(self)38 unsafe fn woefully_underdocumented(self); 39 40 /// # Safety at_least_somewhat_documented(self)41 unsafe fn at_least_somewhat_documented(self); 42 } 43 44 pub unsafe trait UnsafeTrait { method()45 fn method(); 46 } 47 48 /// # Safety 49 pub unsafe trait DocumentedUnsafeTrait { method2()50 fn method2(); 51 } 52 53 pub struct Struct; 54 55 impl SafeTraitUnsafeMethods for Struct { woefully_underdocumented(self)56 unsafe fn woefully_underdocumented(self) { 57 // all is well 58 } 59 at_least_somewhat_documented(self)60 unsafe fn at_least_somewhat_documented(self) { 61 // all is still well 62 } 63 } 64 65 unsafe impl UnsafeTrait for Struct { method()66 fn method() {} 67 } 68 69 unsafe impl DocumentedUnsafeTrait for Struct { method2()70 fn method2() {} 71 } 72 73 impl Struct { more_undocumented_unsafe() -> Self74 pub unsafe fn more_undocumented_unsafe() -> Self { 75 unimplemented!(); 76 } 77 78 /// # Safety somewhat_documented(&self)79 pub unsafe fn somewhat_documented(&self) { 80 unimplemented!(); 81 } 82 private(&self)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 main()108fn 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 { f()125 pub unsafe fn f() {} 126 } 127 } 128 129 /// # Implementation safety 130 pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader { method()131 fn method(); 132 } 133