File tree 5 files changed +43
-7
lines changed
5 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -236,7 +236,17 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
236
236
hir:: ItemKind :: Impl ( ref impl_) => {
237
237
self . in_trait_impl = impl_. of_trait . is_some ( ) ;
238
238
} ,
239
- _ => { } ,
239
+ hir:: ItemKind :: Trait ( _, unsafety, ..) => {
240
+ if !headers. safety && unsafety == hir:: Unsafety :: Unsafe {
241
+ span_lint (
242
+ cx,
243
+ MISSING_SAFETY_DOC ,
244
+ item. span ,
245
+ "docs for unsafe trait missing `# Safety` section" ,
246
+ ) ;
247
+ }
248
+ } ,
249
+ _ => ( ) ,
240
250
}
241
251
}
242
252
Original file line number Diff line number Diff line change 3
3
4
4
#![ feature( no_core, lang_items, start) ]
5
5
#![ no_core]
6
+ #![ allow( clippy:: missing_safety_doc) ]
6
7
7
8
#[ link( name = "c" ) ]
8
9
extern "C" { }
Original file line number Diff line number Diff line change 1
1
error: methods called `as_*` usually take `self` by reference or `self` by mutable reference
2
- --> $DIR/def_id_nocore.rs:26 :19
2
+ --> $DIR/def_id_nocore.rs:27 :19
3
3
|
4
4
LL | pub fn as_ref(self) -> &'static str {
5
5
| ^^^^
Original file line number Diff line number Diff line change @@ -34,16 +34,25 @@ mod private_mod {
34
34
35
35
pub use private_mod:: republished;
36
36
37
- pub trait UnsafeTrait {
37
+ pub trait SafeTraitUnsafeMethods {
38
38
unsafe fn woefully_underdocumented ( self ) ;
39
39
40
40
/// # Safety
41
41
unsafe fn at_least_somewhat_documented ( self ) ;
42
42
}
43
43
44
+ pub unsafe trait UnsafeTrait {
45
+ fn method ( ) ;
46
+ }
47
+
48
+ /// # Safety
49
+ pub unsafe trait DocumentedUnsafeTrait {
50
+ fn method2 ( ) ;
51
+ }
52
+
44
53
pub struct Struct ;
45
54
46
- impl UnsafeTrait for Struct {
55
+ impl SafeTraitUnsafeMethods for Struct {
47
56
unsafe fn woefully_underdocumented ( self ) {
48
57
// all is well
49
58
}
@@ -53,6 +62,14 @@ impl UnsafeTrait for Struct {
53
62
}
54
63
}
55
64
65
+ unsafe impl UnsafeTrait for Struct {
66
+ fn method ( ) { }
67
+ }
68
+
69
+ unsafe impl DocumentedUnsafeTrait for Struct {
70
+ fn method2 ( ) { }
71
+ }
72
+
56
73
impl Struct {
57
74
pub unsafe fn more_undocumented_unsafe ( ) -> Self {
58
75
unimplemented ! ( ) ;
Original file line number Diff line number Diff line change @@ -22,16 +22,24 @@ error: unsafe function's docs miss `# Safety` section
22
22
LL | unsafe fn woefully_underdocumented(self);
23
23
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24
24
25
+ error: docs for unsafe trait missing `# Safety` section
26
+ --> $DIR/doc_unsafe.rs:44:1
27
+ |
28
+ LL | / pub unsafe trait UnsafeTrait {
29
+ LL | | fn method();
30
+ LL | | }
31
+ | |_^
32
+
25
33
error: unsafe function's docs miss `# Safety` section
26
- --> $DIR/doc_unsafe.rs:57 :5
34
+ --> $DIR/doc_unsafe.rs:74 :5
27
35
|
28
36
LL | / pub unsafe fn more_undocumented_unsafe() -> Self {
29
37
LL | | unimplemented!();
30
38
LL | | }
31
39
| |_____^
32
40
33
41
error: unsafe function's docs miss `# Safety` section
34
- --> $DIR/doc_unsafe.rs:73 :9
42
+ --> $DIR/doc_unsafe.rs:90 :9
35
43
|
36
44
LL | / pub unsafe fn whee() {
37
45
LL | | unimplemented!()
@@ -43,5 +51,5 @@ LL | very_unsafe!();
43
51
|
44
52
= note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)
45
53
46
- error: aborting due to 5 previous errors
54
+ error: aborting due to 6 previous errors
47
55
You can’t perform that action at this time.
0 commit comments