Skip to content

Commit 9b33cd6

Browse files
committed
Rework missing_docs_in_private_items:
* Don't search spans between items for comments. * Don't lint items inside bodies, automatically derived impls. * Don't lint items inside macro generated modules unless they are namable outside. * Delay `is_from_proc_macro` checks * Handle reexports when checking if an item is reachable from the crate root. * Don't lint the crate root.
1 parent fc811f7 commit 9b33cd6

File tree

10 files changed

+370
-387
lines changed

10 files changed

+370
-387
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 215 additions & 204 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
1-
error: missing documentation for a struct field
1+
error: missing documentation for field
22
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:10:5
33
|
44
LL | field3: i32,
5-
| ^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]`
99

10-
error: missing documentation for a struct
11-
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:13:1
10+
error: missing documentation for item
11+
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:13:8
1212
|
13-
LL | / struct Test2 {
14-
LL | |
15-
LL | | _field1: i32, // This should not trigger a warning
16-
LL | | _field2: i32, // This should not trigger a warning
17-
LL | | }
18-
| |_^
13+
LL | struct Test2 {
14+
| ^^^^^
1915

20-
error: missing documentation for a struct
21-
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:19:1
16+
error: missing documentation for item
17+
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:19:8
2218
|
23-
LL | / struct Test3 {
24-
LL | |
25-
LL | | /// This field is documented although this is not mandatory
26-
LL | | _unused: i32, // This should not trigger a warning because it starts with an underscore
27-
LL | | field2: i32,
28-
LL | | }
29-
| |_^
19+
LL | struct Test3 {
20+
| ^^^^^
3021

31-
error: missing documentation for a struct field
22+
error: missing documentation for field
3223
--> tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs:23:5
3324
|
3425
LL | field2: i32,
35-
| ^^^^^^^^^^^
26+
| ^^^^^^
3627

3728
error: aborting due to 4 previous errors
3829

tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ mod my_mod {
2424
/// some docs
2525
pub(crate) fn sub_crate_with_docs() {}
2626
pub(crate) fn sub_crate_no_docs() {}
27-
//~^ missing_docs_in_private_items
2827
/// some docs
2928
pub(super) fn sub_super_with_docs() {}
3029
pub(super) fn sub_super_no_docs() {}
Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,41 @@
1-
error: missing documentation for a function
2-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:13:5
1+
error: missing documentation for item
2+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:13:19
33
|
44
LL | pub(crate) fn crate_no_docs() {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]`
99

10-
error: missing documentation for a function
11-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:17:5
10+
error: missing documentation for item
11+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:17:19
1212
|
1313
LL | pub(super) fn super_no_docs() {}
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| ^^^^^^^^^^^^^
1515

16-
error: missing documentation for a function
17-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:26:9
18-
|
19-
LL | pub(crate) fn sub_crate_no_docs() {}
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22-
error: missing documentation for a struct field
23-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:37:9
16+
error: missing documentation for field
17+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:36:20
2418
|
2519
LL | pub(crate) crate_field_no_docs: (),
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| ^^^^^^^^^^^^^^^^^^^
2721

28-
error: missing documentation for a struct
29-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:44:5
22+
error: missing documentation for item
23+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:43:23
3024
|
31-
LL | / pub(crate) struct CrateStructNoDocs {
32-
LL | |
33-
LL | | /// some docs
34-
LL | | pub(crate) crate_field_with_docs: (),
35-
... |
36-
LL | | priv_field_no_docs: (),
37-
LL | | }
38-
| |_____^
25+
LL | pub(crate) struct CrateStructNoDocs {
26+
| ^^^^^^^^^^^^^^^^^
3927

40-
error: missing documentation for a struct field
41-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:48:9
28+
error: missing documentation for field
29+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:47:20
4230
|
4331
LL | pub(crate) crate_field_no_docs: (),
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
| ^^^^^^^^^^^^^^^^^^^
4533

46-
error: missing documentation for a type alias
47-
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:58:1
34+
error: missing documentation for item
35+
--> tests/ui-toml/pub_crate_missing_docs/pub_crate_missing_doc.rs:57:6
4836
|
4937
LL | type CrateTypedefNoDocs = String;
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
| ^^^^^^^^^^^^^^^^^^
5139

52-
error: aborting due to 7 previous errors
40+
error: aborting due to 6 previous errors
5341

tests/ui/missing_doc.rs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
//@needs-asm-support
22
//@aux-build: proc_macros.rs
3-
//@aux-build: proc_macro_attr.rs
43

54
#![warn(clippy::missing_docs_in_private_items)]
6-
// When denying at the crate level, be sure to not get random warnings from the
7-
// injected intrinsics by the compiler.
8-
#![allow(dead_code)]
9-
//! Some garbage docs for the crate here
10-
#![doc = "More garbage"]
11-
12-
#[macro_use]
13-
extern crate proc_macro_attr;
5+
#![allow(dead_code, non_local_definitions)]
6+
147
extern crate proc_macros;
158

169
use proc_macros::with_span;
@@ -138,11 +131,53 @@ fn issue13298() {
138131
const MSG: &str = "Hello, world!";
139132
}
140133

141-
// issue #12197
142-
// Undocumented field originated inside of spanned proc-macro attribute
143-
/// Some dox for struct.
144-
#[rewrite_struct]
145-
pub struct Test {
146-
/// Dox
147-
a: u8,
134+
with_span!(span
135+
/// docs
136+
struct WithInternalHelper {
137+
__helper: u32,
138+
$(
139+
field: u32, //~ missing_docs_in_private_items
140+
/// docs
141+
field2: u32,
142+
)
143+
}
144+
145+
const _: () = {
146+
struct Internal {
147+
__helper: u32,
148+
$(field: u32),
149+
$(field2: u32),
150+
};
151+
impl WithInternalHelper {
152+
pub(crate) fn internal(self) -> Internal {
153+
unimplemented!()
154+
}
155+
}
156+
};
157+
);
158+
159+
/// docs
160+
struct WithHiddenImpl;
161+
162+
/// docs
163+
fn with_hidden_impl() {
164+
mod m {
165+
struct Bar;
166+
const _: () = {
167+
mod m2 {
168+
impl super::Bar {
169+
pub fn bar() {
170+
impl crate::WithHiddenImpl {
171+
pub(crate) fn visible(&self) {}
172+
}
173+
}
174+
}
175+
}
176+
177+
#[automatically_derived]
178+
impl crate::WithHiddenImpl {
179+
fn derived(self) {}
180+
}
181+
};
182+
}
148183
}

tests/ui/missing_doc.stderr

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,95 @@
1-
error: missing documentation for a type alias
2-
--> tests/ui/missing_doc.rs:19:1
1+
error: missing documentation for item
2+
--> tests/ui/missing_doc.rs:12:6
33
|
44
LL | type Typedef = String;
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^
66
|
77
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::missing_docs_in_private_items)]`
99

10-
error: missing documentation for a module
11-
--> tests/ui/missing_doc.rs:23:1
10+
error: missing documentation for item
11+
--> tests/ui/missing_doc.rs:16:5
1212
|
1313
LL | mod module_no_dox {}
14-
| ^^^^^^^^^^^^^^^^^^^^
14+
| ^^^^^^^^^^^^^
1515

16-
error: missing documentation for a function
17-
--> tests/ui/missing_doc.rs:30:1
16+
error: missing documentation for item
17+
--> tests/ui/missing_doc.rs:23:4
1818
|
1919
LL | fn foo3() {}
20-
| ^^^^^^^^^^^^
20+
| ^^^^
2121

22-
error: missing documentation for an enum
23-
--> tests/ui/missing_doc.rs:45:1
22+
error: missing documentation for item
23+
--> tests/ui/missing_doc.rs:38:6
2424
|
25-
LL | / enum Baz {
26-
LL | |
27-
LL | | BazA { a: isize, b: isize },
28-
... |
29-
LL | | }
30-
| |_^
25+
LL | enum Baz {
26+
| ^^^
3127

32-
error: missing documentation for a variant
33-
--> tests/ui/missing_doc.rs:47:5
28+
error: missing documentation for variant
29+
--> tests/ui/missing_doc.rs:40:5
3430
|
3531
LL | BazA { a: isize, b: isize },
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
| ^^^^
3733

38-
error: missing documentation for a struct field
39-
--> tests/ui/missing_doc.rs:47:12
34+
error: missing documentation for field
35+
--> tests/ui/missing_doc.rs:40:12
4036
|
4137
LL | BazA { a: isize, b: isize },
42-
| ^^^^^^^^
38+
| ^
4339

44-
error: missing documentation for a struct field
45-
--> tests/ui/missing_doc.rs:47:22
40+
error: missing documentation for field
41+
--> tests/ui/missing_doc.rs:40:22
4642
|
4743
LL | BazA { a: isize, b: isize },
48-
| ^^^^^^^^
44+
| ^
4945

50-
error: missing documentation for a variant
51-
--> tests/ui/missing_doc.rs:51:5
46+
error: missing documentation for variant
47+
--> tests/ui/missing_doc.rs:44:5
5248
|
5349
LL | BarB,
5450
| ^^^^
5551

56-
error: missing documentation for a constant
57-
--> tests/ui/missing_doc.rs:76:1
52+
error: missing documentation for item
53+
--> tests/ui/missing_doc.rs:69:7
5854
|
5955
LL | const FOO: u32 = 0;
60-
| ^^^^^^^^^^^^^^^^^^^
56+
| ^^^
6157

62-
error: missing documentation for a static
63-
--> tests/ui/missing_doc.rs:86:1
58+
error: missing documentation for item
59+
--> tests/ui/missing_doc.rs:79:8
6460
|
6561
LL | static BAR: u32 = 0;
66-
| ^^^^^^^^^^^^^^^^^^^^
62+
| ^^^
6763

68-
error: missing documentation for a module
69-
--> tests/ui/missing_doc.rs:96:1
64+
error: missing documentation for item
65+
--> tests/ui/missing_doc.rs:89:5
7066
|
71-
LL | / mod internal_impl {
72-
LL | |
73-
LL | | /// dox
74-
LL | | pub fn documented() {}
75-
... |
76-
LL | | }
77-
| |_^
67+
LL | mod internal_impl {
68+
| ^^^^^^^^^^^^^
7869

79-
error: missing documentation for a function
80-
--> tests/ui/missing_doc.rs:102:5
70+
error: missing documentation for item
71+
--> tests/ui/missing_doc.rs:95:8
8172
|
8273
LL | fn undocumented3() {}
83-
| ^^^^^^^^^^^^^^^^^^^^^
74+
| ^^^^^^^^^^^^^
8475

85-
error: missing documentation for a function
86-
--> tests/ui/missing_doc.rs:109:9
76+
error: missing documentation for item
77+
--> tests/ui/missing_doc.rs:102:12
8778
|
8879
LL | fn also_undocumented2() {}
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
| ^^^^^^^^^^^^^^^^^^
81+
82+
error: missing documentation for item
83+
--> tests/ui/missing_doc.rs:128:4
84+
|
85+
LL | fn issue13298() {
86+
| ^^^^^^^^^^
9087

91-
error: missing documentation for a function
92-
--> tests/ui/missing_doc.rs:135:1
88+
error: missing documentation for field
89+
--> tests/ui/missing_doc.rs:139:13
9390
|
94-
LL | / fn issue13298() {
95-
LL | |
96-
LL | | // Rustdoc doesn't generate documentation for items within other items like fns or consts
97-
LL | | const MSG: &str = "Hello, world!";
98-
LL | | }
99-
| |_^
91+
LL | field: u32,
92+
| ^^^^^
10093

101-
error: aborting due to 14 previous errors
94+
error: aborting due to 15 previous errors
10295

tests/ui/missing_doc_crate.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/ui/missing_doc_crate_missing.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/ui/missing_doc_crate_missing.stderr

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)