summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unnecessary_unsafety_doc.rs
blob: c160e31afd33b82200b72515da2c6eb9e1ffa09e (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
145
146
147
148
149
// aux-build:doc_unsafe_macros.rs

#![allow(clippy::let_unit_value)]
#![warn(clippy::unnecessary_safety_doc)]

#[macro_use]
extern crate doc_unsafe_macros;

/// This is has no safety section, and does not need one either
pub fn destroy_the_planet() {
    unimplemented!();
}

/// This one does not need a `Safety` section
///
/// # Safety
///
/// This function shouldn't be called unless the horsemen are ready
pub fn apocalypse(universe: &mut ()) {
    unimplemented!();
}

/// This is a private function, skip to match behavior with `missing_safety_doc`.
///
/// # Safety
///
/// Boo!
fn you_dont_see_me() {
    unimplemented!();
}

mod private_mod {
    /// This is public but unexported function, skip to match behavior with `missing_safety_doc`.
    ///
    /// # Safety
    ///
    /// Very safe!
    pub fn only_crate_wide_accessible() {
        unimplemented!();
    }

    /// # Safety
    ///
    /// Unnecessary safety!
    pub fn republished() {
        unimplemented!();
    }
}

pub use private_mod::republished;

pub trait SafeTraitSafeMethods {
    fn woefully_underdocumented(self);

    /// # Safety
    ///
    /// Unnecessary!
    fn documented(self);
}

pub trait SafeTrait {
    fn method();
}

/// # Safety
///
/// Unnecessary!
pub trait DocumentedSafeTrait {
    fn method2();
}

pub struct Struct;

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

    fn documented(self) {
        // all is still well
    }
}

impl SafeTrait for Struct {
    fn method() {}
}

impl DocumentedSafeTrait for Struct {
    fn method2() {}
}

impl Struct {
    /// # Safety
    ///
    /// Unnecessary!
    pub fn documented() -> Self {
        unimplemented!();
    }

    pub fn undocumented(&self) {
        unimplemented!();
    }

    /// Private, fine again to stay consistent with `missing_safety_doc`.
    ///
    /// # Safety
    ///
    /// Unnecessary!
    fn private(&self) {
        unimplemented!();
    }
}

macro_rules! very_safe {
    () => {
        pub fn whee() {
            unimplemented!()
        }

        /// # Safety
        ///
        /// Driving is very safe already!
        pub fn drive() {
            whee()
        }
    };
}

very_safe!();

// we don't lint code from external macros
undocd_safe!();

fn main() {}

// 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 trait DocumentedSafeTraitWithImplementationHeader {
    fn method();
}