1
1
use rustc_ast:: ast:: Attribute ;
2
2
use rustc_errors:: Applicability ;
3
- use rustc_hir:: ItemKind ;
3
+ use rustc_hir:: { Item , ItemKind } ;
4
4
use rustc_lint:: LateContext ;
5
5
6
6
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_then} ;
@@ -10,13 +10,17 @@ use super::TOO_LONG_FIRST_DOC_PARAGRAPH;
10
10
11
11
pub ( super ) fn check (
12
12
cx : & LateContext < ' _ > ,
13
+ item : & Item < ' _ > ,
13
14
attrs : & [ Attribute ] ,
14
- item_kind : ItemKind < ' _ > ,
15
15
mut first_paragraph_len : usize ,
16
+ check_private_items : bool ,
16
17
) {
17
- if first_paragraph_len <= 100
18
+ if !check_private_items && !cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
19
+ return ;
20
+ }
21
+ if first_paragraph_len <= 200
18
22
|| !matches ! (
19
- item_kind ,
23
+ item . kind ,
20
24
ItemKind :: Static ( ..)
21
25
| ItemKind :: Const ( ..)
22
26
| ItemKind :: Fn ( ..)
@@ -32,6 +36,7 @@ pub(super) fn check(
32
36
{
33
37
return ;
34
38
}
39
+
35
40
let mut spans = Vec :: new ( ) ;
36
41
let mut should_suggest_empty_doc = false ;
37
42
@@ -42,7 +47,7 @@ pub(super) fn check(
42
47
let doc = doc. trim ( ) ;
43
48
if spans. len ( ) == 1 {
44
49
// We make this suggestion only if the first doc line ends with a punctuation
45
- // because if might just need to add an empty line with `///`.
50
+ // because it might just need to add an empty line with `///`.
46
51
should_suggest_empty_doc = doc. ends_with ( '.' ) || doc. ends_with ( '!' ) || doc. ends_with ( '?' ) ;
47
52
}
48
53
let len = doc. chars ( ) . count ( ) ;
@@ -68,7 +73,7 @@ pub(super) fn check(
68
73
|diag| {
69
74
diag. span_suggestion (
70
75
new_span,
71
- "add" ,
76
+ "add an empty line " ,
72
77
format ! ( "{snippet}///\n " ) ,
73
78
Applicability :: MachineApplicable ,
74
79
) ;
0 commit comments