Skip to content

Commit ba86a99

Browse files
committed
Auto merge of #10324 - andrewbanchich:fix-missing-private-docs, r=dswij
Scope `missing_docs_in_private_items` to only private items `missing_docs_in_private_items` currently detects missing docs for public items as well as private. Since `missing_docs`already covers public items, this PR updates `missing_docs_in_private_items` to only cover private items. Fixes #1895 changelog: [`missing_docs_in_private_items`]: Apply lint only to private items (used to be public and private)
2 parents d988734 + 49a06ed commit ba86a99

File tree

3 files changed

+8
-128
lines changed

3 files changed

+8
-128
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use clippy_utils::attrs::is_doc_hidden;
99
use clippy_utils::diagnostics::span_lint;
1010
use clippy_utils::is_from_proc_macro;
11-
use hir::def_id::LocalDefId;
1211
use if_chain::if_chain;
1312
use rustc_ast::ast::{self, MetaItem, MetaItemKind};
1413
use rustc_hir as hir;
14+
use rustc_hir::def_id::LocalDefId;
1515
use rustc_lint::{LateContext, LateLintPass, LintContext};
1616
use rustc_middle::ty::{DefIdTree, Visibility};
1717
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -21,8 +21,7 @@ use rustc_span::sym;
2121

2222
declare_clippy_lint! {
2323
/// ### What it does
24-
/// Warns if there is missing doc for any documentable item
25-
/// (public or private).
24+
/// Warns if there is missing doc for any private documentable item
2625
///
2726
/// ### Why is this bad?
2827
/// Doc is good. *rustc* has a `MISSING_DOCS`
@@ -32,7 +31,7 @@ declare_clippy_lint! {
3231
#[clippy::version = "pre 1.29.0"]
3332
pub MISSING_DOCS_IN_PRIVATE_ITEMS,
3433
restriction,
35-
"detects missing documentation for public and private members"
34+
"detects missing documentation for private members"
3635
}
3736

3837
pub struct MissingDoc {
@@ -107,11 +106,14 @@ impl MissingDoc {
107106
if vis == Visibility::Public || vis != Visibility::Restricted(CRATE_DEF_ID.into()) {
108107
return;
109108
}
109+
} else if def_id != CRATE_DEF_ID && cx.effective_visibilities.is_exported(def_id) {
110+
return;
110111
}
111112

112113
let has_doc = attrs
113114
.iter()
114115
.any(|a| a.doc_str().is_some() || Self::has_include(a.meta()));
116+
115117
if !has_doc {
116118
span_lint(
117119
cx,

tests/ui/missing_doc.stderr

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,12 @@ LL | type Typedef = String;
66
|
77
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
88

9-
error: missing documentation for a type alias
10-
--> $DIR/missing_doc.rs:17:1
11-
|
12-
LL | pub type PubTypedef = String;
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
159
error: missing documentation for a module
1610
--> $DIR/missing_doc.rs:19:1
1711
|
1812
LL | mod module_no_dox {}
1913
| ^^^^^^^^^^^^^^^^^^^^
2014

21-
error: missing documentation for a module
22-
--> $DIR/missing_doc.rs:20:1
23-
|
24-
LL | pub mod pub_module_no_dox {}
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26-
27-
error: missing documentation for a function
28-
--> $DIR/missing_doc.rs:24:1
29-
|
30-
LL | pub fn foo2() {}
31-
| ^^^^^^^^^^^^^^^^
32-
3315
error: missing documentation for a function
3416
--> $DIR/missing_doc.rs:25:1
3517
|
@@ -69,50 +51,18 @@ error: missing documentation for a variant
6951
LL | BarB,
7052
| ^^^^
7153

72-
error: missing documentation for an enum
73-
--> $DIR/missing_doc.rs:44:1
74-
|
75-
LL | / pub enum PubBaz {
76-
LL | | PubBazA { a: isize },
77-
LL | | }
78-
| |_^
79-
80-
error: missing documentation for a variant
81-
--> $DIR/missing_doc.rs:45:5
82-
|
83-
LL | PubBazA { a: isize },
84-
| ^^^^^^^^^^^^^^^^^^^^
85-
86-
error: missing documentation for a struct field
87-
--> $DIR/missing_doc.rs:45:15
88-
|
89-
LL | PubBazA { a: isize },
90-
| ^^^^^^^^
91-
9254
error: missing documentation for a constant
9355
--> $DIR/missing_doc.rs:65:1
9456
|
9557
LL | const FOO: u32 = 0;
9658
| ^^^^^^^^^^^^^^^^^^^
9759

98-
error: missing documentation for a constant
99-
--> $DIR/missing_doc.rs:72:1
100-
|
101-
LL | pub const FOO4: u32 = 0;
102-
| ^^^^^^^^^^^^^^^^^^^^^^^^
103-
10460
error: missing documentation for a static
10561
--> $DIR/missing_doc.rs:74:1
10662
|
10763
LL | static BAR: u32 = 0;
10864
| ^^^^^^^^^^^^^^^^^^^^
10965

110-
error: missing documentation for a static
111-
--> $DIR/missing_doc.rs:81:1
112-
|
113-
LL | pub static BAR4: u32 = 0;
114-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
115-
11666
error: missing documentation for a module
11767
--> $DIR/missing_doc.rs:83:1
11868
|
@@ -125,35 +75,17 @@ LL | | }
12575
LL | | }
12676
| |_^
12777

128-
error: missing documentation for a function
129-
--> $DIR/missing_doc.rs:86:5
130-
|
131-
LL | pub fn undocumented1() {}
132-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
133-
134-
error: missing documentation for a function
135-
--> $DIR/missing_doc.rs:87:5
136-
|
137-
LL | pub fn undocumented2() {}
138-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
139-
14078
error: missing documentation for a function
14179
--> $DIR/missing_doc.rs:88:5
14280
|
14381
LL | fn undocumented3() {}
14482
| ^^^^^^^^^^^^^^^^^^^^^
14583

146-
error: missing documentation for a function
147-
--> $DIR/missing_doc.rs:93:9
148-
|
149-
LL | pub fn also_undocumented1() {}
150-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151-
15284
error: missing documentation for a function
15385
--> $DIR/missing_doc.rs:94:9
15486
|
15587
LL | fn also_undocumented2() {}
15688
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
15789

158-
error: aborting due to 24 previous errors
90+
error: aborting due to 13 previous errors
15991

tests/ui/missing_doc_impl.stderr

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,60 +21,12 @@ error: missing documentation for a struct field
2121
LL | b: isize,
2222
| ^^^^^^^^
2323

24-
error: missing documentation for a struct
25-
--> $DIR/missing_doc_impl.rs:18:1
26-
|
27-
LL | / pub struct PubFoo {
28-
LL | | pub a: isize,
29-
LL | | b: isize,
30-
LL | | }
31-
| |_^
32-
33-
error: missing documentation for a struct field
34-
--> $DIR/missing_doc_impl.rs:19:5
35-
|
36-
LL | pub a: isize,
37-
| ^^^^^^^^^^^^
38-
3924
error: missing documentation for a struct field
4025
--> $DIR/missing_doc_impl.rs:20:5
4126
|
4227
LL | b: isize,
4328
| ^^^^^^^^
4429

45-
error: missing documentation for a trait
46-
--> $DIR/missing_doc_impl.rs:43:1
47-
|
48-
LL | / pub trait C {
49-
LL | | fn foo(&self);
50-
LL | | fn foo_with_impl(&self) {}
51-
LL | | }
52-
| |_^
53-
54-
error: missing documentation for a method
55-
--> $DIR/missing_doc_impl.rs:44:5
56-
|
57-
LL | fn foo(&self);
58-
| ^^^^^^^^^^^^^^
59-
60-
error: missing documentation for a method
61-
--> $DIR/missing_doc_impl.rs:45:5
62-
|
63-
LL | fn foo_with_impl(&self) {}
64-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
65-
66-
error: missing documentation for an associated type
67-
--> $DIR/missing_doc_impl.rs:55:5
68-
|
69-
LL | type AssociatedType;
70-
| ^^^^^^^^^^^^^^^^^^^^
71-
72-
error: missing documentation for an associated type
73-
--> $DIR/missing_doc_impl.rs:56:5
74-
|
75-
LL | type AssociatedTypeDef = Self;
76-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77-
7830
error: missing documentation for an associated function
7931
--> $DIR/missing_doc_impl.rs:67:5
8032
|
@@ -89,12 +41,6 @@ error: missing documentation for an associated function
8941
LL | fn bar() {}
9042
| ^^^^^^^^^^^
9143

92-
error: missing documentation for an associated function
93-
--> $DIR/missing_doc_impl.rs:74:5
94-
|
95-
LL | pub fn foo() {}
96-
| ^^^^^^^^^^^^^^^
97-
9844
error: missing documentation for an associated function
9945
--> $DIR/missing_doc_impl.rs:78:5
10046
|
@@ -103,5 +49,5 @@ LL | | 1
10349
LL | | }
10450
| |_____^
10551

106-
error: aborting due to 15 previous errors
52+
error: aborting due to 7 previous errors
10753

0 commit comments

Comments
 (0)