File tree Expand file tree Collapse file tree 5 files changed +43
-7
lines changed Expand file tree Collapse file tree 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 {
236236 hir:: ItemKind :: Impl ( ref impl_) => {
237237 self . in_trait_impl = impl_. of_trait . is_some ( ) ;
238238 } ,
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+ _ => ( ) ,
240250 }
241251 }
242252
Original file line number Diff line number Diff line change 33
44#![ feature( no_core, lang_items, start) ]
55#![ no_core]
6+ #![ allow( clippy:: missing_safety_doc) ]
67
78#[ link( name = "c" ) ]
89extern "C" { }
Original file line number Diff line number Diff line change 11error: 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
33 |
44LL | pub fn as_ref(self) -> &'static str {
55 | ^^^^
Original file line number Diff line number Diff line change @@ -34,16 +34,25 @@ mod private_mod {
3434
3535pub use private_mod:: republished;
3636
37- pub trait UnsafeTrait {
37+ pub trait SafeTraitUnsafeMethods {
3838 unsafe fn woefully_underdocumented ( self ) ;
3939
4040 /// # Safety
4141 unsafe fn at_least_somewhat_documented ( self ) ;
4242}
4343
44+ pub unsafe trait UnsafeTrait {
45+ fn method ( ) ;
46+ }
47+
48+ /// # Safety
49+ pub unsafe trait DocumentedUnsafeTrait {
50+ fn method2 ( ) ;
51+ }
52+
4453pub struct Struct ;
4554
46- impl UnsafeTrait for Struct {
55+ impl SafeTraitUnsafeMethods for Struct {
4756 unsafe fn woefully_underdocumented ( self ) {
4857 // all is well
4958 }
@@ -53,6 +62,14 @@ impl UnsafeTrait for Struct {
5362 }
5463}
5564
65+ unsafe impl UnsafeTrait for Struct {
66+ fn method ( ) { }
67+ }
68+
69+ unsafe impl DocumentedUnsafeTrait for Struct {
70+ fn method2 ( ) { }
71+ }
72+
5673impl Struct {
5774 pub unsafe fn more_undocumented_unsafe ( ) -> Self {
5875 unimplemented ! ( ) ;
Original file line number Diff line number Diff line change @@ -22,16 +22,24 @@ error: unsafe function's docs miss `# Safety` section
2222LL | unsafe fn woefully_underdocumented(self);
2323 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
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+
2533error: unsafe function's docs miss `# Safety` section
26- --> $DIR/doc_unsafe.rs:57 :5
34+ --> $DIR/doc_unsafe.rs:74 :5
2735 |
2836LL | / pub unsafe fn more_undocumented_unsafe() -> Self {
2937LL | | unimplemented!();
3038LL | | }
3139 | |_____^
3240
3341error: unsafe function's docs miss `# Safety` section
34- --> $DIR/doc_unsafe.rs:73 :9
42+ --> $DIR/doc_unsafe.rs:90 :9
3543 |
3644LL | / pub unsafe fn whee() {
3745LL | | unimplemented!()
@@ -43,5 +51,5 @@ LL | very_unsafe!();
4351 |
4452 = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)
4553
46- error: aborting due to 5 previous errors
54+ error: aborting due to 6 previous errors
4755
You can’t perform that action at this time.
0 commit comments