]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/doc_unsafe.rs
New upstream version 1.57.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / doc_unsafe.rs
CommitLineData
f20569fa
XL
1// aux-build:doc_unsafe_macros.rs
2
3#[macro_use]
4extern crate doc_unsafe_macros;
5
6/// This is not sufficiently documented
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
16pub unsafe fn apocalypse(universe: &mut ()) {
17 unimplemented!();
18}
19
20/// This is a private function, so docs aren't necessary
21unsafe fn you_dont_see_me() {
22 unimplemented!();
23}
24
25mod private_mod {
26 pub unsafe fn only_crate_wide_accessible() {
27 unimplemented!();
28 }
29
30 pub unsafe fn republished() {
31 unimplemented!();
32 }
33}
34
35pub use private_mod::republished;
36
c295e0f8 37pub 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
44pub unsafe trait UnsafeTrait {
45 fn method();
46}
47
48/// # Safety
49pub unsafe trait DocumentedUnsafeTrait {
50 fn method2();
51}
52
f20569fa
XL
53pub struct Struct;
54
c295e0f8 55impl 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
65unsafe impl UnsafeTrait for Struct {
66 fn method() {}
67}
68
69unsafe impl DocumentedUnsafeTrait for Struct {
70 fn method2() {}
71}
72
f20569fa
XL
73impl 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
88macro_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
103very_unsafe!();
104
105// we don't lint code from external macros
106undocd_unsafe!();
107
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}