Skip to content

Commit d84d9d3

Browse files
committed
lint on variant and fields as well
1 parent f066be7 commit d84d9d3

File tree

3 files changed

+109
-63
lines changed

3 files changed

+109
-63
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
399399
check_attrs(cx, &self.valid_idents, attrs);
400400
}
401401

402+
fn check_variant(&mut self, cx: &LateContext<'tcx>, variant: &'tcx hir::Variant<'tcx>) {
403+
let attrs = cx.tcx.hir().attrs(variant.hir_id);
404+
check_attrs(cx, &self.valid_idents, attrs);
405+
}
406+
407+
fn check_field_def(&mut self, cx: &LateContext<'tcx>, variant: &'tcx hir::FieldDef<'tcx>) {
408+
let attrs = cx.tcx.hir().attrs(variant.hir_id);
409+
check_attrs(cx, &self.valid_idents, attrs);
410+
}
411+
402412
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
403413
let attrs = cx.tcx.hir().attrs(item.hir_id());
404414
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {

tests/ui/empty_docs.rs

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
#![allow(unused)]
22
#![warn(clippy::empty_docs)]
3+
mod outer {
4+
//!
35
4-
/// this is a struct
5-
struct Bananas {
6-
/// count
7-
count: usize,
8-
}
6+
/// this is a struct
7+
struct Bananas {
8+
/// count
9+
count: usize,
10+
}
911

10-
///
11-
enum Warn {
1212
///
13-
A,
14-
///
15-
B,
16-
}
13+
enum Warn {
14+
///
15+
A,
16+
B,
17+
}
1718

18-
enum WarnA {
19-
///
20-
A,
21-
B,
22-
}
19+
enum DontWarn {
20+
/// i
21+
A,
22+
B,
23+
}
2324

24-
enum DontWarn {
25-
/// it's ok
26-
A,
27-
///
28-
B,
29-
}
25+
#[doc = ""]
26+
fn warn_about_this() {}
3027

31-
#[doc = ""]
32-
fn warn_about_this() {}
28+
#[doc = ""]
29+
#[doc = ""]
30+
fn this_doesn_warn() {}
3331

34-
#[doc = ""]
35-
#[doc = ""]
36-
fn this_doesn_warn() {}
32+
#[doc = "a fine function"]
33+
fn this_is_fine() {}
3734

38-
#[doc = "a fine function"]
39-
fn this_is_fine() {}
35+
///
36+
mod inner {
37+
///
38+
fn dont_warn_inner_outer() {
39+
//!w
40+
}
4041

41-
fn warn_about_this_as_well() {
42-
//!
43-
}
42+
fn this_is_ok() {
43+
//!
44+
//! inside the function
45+
}
4446

45-
///
46-
fn warn_inner_outer() {
47-
//!w
48-
}
47+
fn warn() {
48+
/*! */
49+
}
4950

50-
fn this_is_ok() {
51-
//!
52-
//! inside the function
53-
}
51+
fn dont_warn() {
52+
/*! dont warn me */
53+
}
5454

55-
fn warn() {
56-
/*! */
57-
}
55+
trait NoDoc {
56+
///
57+
fn some() {}
58+
}
59+
}
5860

59-
fn dont_warn() {
60-
/*! dont warn me */
61+
union Unite {
62+
/// lint y
63+
x: i32,
64+
///
65+
y: i32,
66+
}
6167
}
62-
63-
trait NoDoc {}

tests/ui/empty_docs.stderr

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,77 @@
11
error: empty doc comment
2-
--> tests/ui/empty_docs.rs:10:1
2+
--> tests/ui/empty_docs.rs:4:5
33
|
4-
LL | ///
5-
| ^^^
4+
LL | //!
5+
| ^^^
66
|
77
= help: consider removing or filling it
88
= note: `-D clippy::empty-docs` implied by `-D warnings`
99
= help: to override `-D warnings` add `#[allow(clippy::empty_docs)]`
1010

1111
error: empty doc comment
12-
--> tests/ui/empty_docs.rs:31:1
12+
--> tests/ui/empty_docs.rs:12:5
1313
|
14-
LL | #[doc = ""]
15-
| ^^^^^^^^^^^
14+
LL | ///
15+
| ^^^
1616
|
1717
= help: consider removing or filling it
1818

1919
error: empty doc comment
20-
--> tests/ui/empty_docs.rs:34:1
20+
--> tests/ui/empty_docs.rs:14:9
2121
|
22-
LL | / #[doc = ""]
23-
LL | | #[doc = ""]
24-
| |___________^
22+
LL | ///
23+
| ^^^
2524
|
2625
= help: consider removing or filling it
2726

2827
error: empty doc comment
29-
--> tests/ui/empty_docs.rs:42:5
28+
--> tests/ui/empty_docs.rs:25:5
3029
|
31-
LL | //!
30+
LL | #[doc = ""]
31+
| ^^^^^^^^^^^
32+
|
33+
= help: consider removing or filling it
34+
35+
error: empty doc comment
36+
--> tests/ui/empty_docs.rs:28:5
37+
|
38+
LL | / #[doc = ""]
39+
LL | | #[doc = ""]
40+
| |_______________^
41+
|
42+
= help: consider removing or filling it
43+
44+
error: empty doc comment
45+
--> tests/ui/empty_docs.rs:35:5
46+
|
47+
LL | ///
3248
| ^^^
3349
|
3450
= help: consider removing or filling it
3551

3652
error: empty doc comment
37-
--> tests/ui/empty_docs.rs:56:5
53+
--> tests/ui/empty_docs.rs:48:13
54+
|
55+
LL | /*! */
56+
| ^^^^^^
57+
|
58+
= help: consider removing or filling it
59+
60+
error: empty doc comment
61+
--> tests/ui/empty_docs.rs:56:13
62+
|
63+
LL | ///
64+
| ^^^
65+
|
66+
= help: consider removing or filling it
67+
68+
error: empty doc comment
69+
--> tests/ui/empty_docs.rs:64:9
3870
|
39-
LL | /*! */
40-
| ^^^^^^
71+
LL | ///
72+
| ^^^
4173
|
4274
= help: consider removing or filling it
4375

44-
error: aborting due to 5 previous errors
76+
error: aborting due to 9 previous errors
4577

0 commit comments

Comments
 (0)