about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/doc_unsafe.rs
blob: 7146fd7941ab011cae230632d81d56253a40a8df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//@aux-build:proc_macros.rs

#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)]

extern crate proc_macros;
use proc_macros::external;

/// This is not sufficiently documented
pub unsafe fn destroy_the_planet() {
    //~^ missing_safety_doc
    unimplemented!();
}

/// This one is
///
/// # Safety
///
/// This function shouldn't be called unless the horsemen are ready
pub unsafe fn apocalypse(universe: &mut ()) {
    unimplemented!();
}

/// This is a private function, so docs aren't necessary
unsafe fn you_dont_see_me() {
    unimplemented!();
}

mod private_mod {
    pub unsafe fn only_crate_wide_accessible() {
        unimplemented!();
    }

    pub unsafe fn republished() {
        //~^ missing_safety_doc
        unimplemented!();
    }
}

pub use private_mod::republished;

pub trait SafeTraitUnsafeMethods {
    unsafe fn woefully_underdocumented(self);
    //~^ missing_safety_doc

    /// # Safety
    unsafe fn at_least_somewhat_documented(self);
}

pub unsafe trait UnsafeTrait {
    //~^ missing_safety_doc
    fn method();
}

/// # Safety
pub unsafe trait DocumentedUnsafeTrait {
    fn method2();
}

pub struct Struct;

impl SafeTraitUnsafeMethods for Struct {
    unsafe fn woefully_underdocumented(self) {
        // all is well
    }

    unsafe fn at_least_somewhat_documented(self) {
        // all is still well
    }
}

unsafe impl UnsafeTrait for Struct {
    fn method() {}
}

unsafe impl DocumentedUnsafeTrait for Struct {
    fn method2() {}
}

impl Struct {
    pub unsafe fn more_undocumented_unsafe() -> Self {
        //~^ missing_safety_doc
        unimplemented!();
    }

    /// # Safety
    pub unsafe fn somewhat_documented(&self) {
        unimplemented!();
    }

    unsafe fn private(&self) {
        unimplemented!();
    }
}

macro_rules! very_unsafe {
    () => {
        pub unsafe fn whee() {
            //~^ missing_safety_doc
            unimplemented!()
        }

        /// # Safety
        ///
        /// Please keep the seat belt fastened
        pub unsafe fn drive() {
            unsafe { whee() }
        }
    };
}

very_unsafe!();

// we don't lint code from external macros
external! {
    pub unsafe fn oy_vey() {
        unimplemented!();
    }
}

fn main() {
    unsafe {
        you_dont_see_me();
        destroy_the_planet();
        let mut universe = ();
        apocalypse(&mut universe);
        private_mod::only_crate_wide_accessible();
        drive();
    }
}

// do not lint if any parent has `#[doc(hidden)]` attribute
// see #7347
#[doc(hidden)]
pub mod __macro {
    pub struct T;
    impl T {
        pub unsafe fn f() {}
    }
}

/// # Implementation safety
pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader {
    fn method();
}