1
1
use super :: { DocHeaders , MISSING_ERRORS_DOC , MISSING_PANICS_DOC , MISSING_SAFETY_DOC , UNNECESSARY_SAFETY_DOC } ;
2
- use clippy_utils:: diagnostics:: { span_lint, span_lint_and_note } ;
2
+ use clippy_utils:: diagnostics:: span_lint;
3
3
use clippy_utils:: macros:: { is_panic, root_macro_call_first_node} ;
4
4
use clippy_utils:: ty:: { get_type_diagnostic_name, implements_trait_with_env, is_type_diagnostic_item} ;
5
5
use clippy_utils:: visitors:: for_each_expr;
@@ -14,7 +14,7 @@ pub fn check(
14
14
cx : & LateContext < ' _ > ,
15
15
owner_id : OwnerId ,
16
16
sig : FnSig < ' _ > ,
17
- headers : DocHeaders ,
17
+ headers : & DocHeaders ,
18
18
body_id : Option < BodyId > ,
19
19
check_private_items : bool ,
20
20
) {
@@ -33,37 +33,38 @@ pub fn check(
33
33
}
34
34
35
35
let span = cx. tcx . def_span ( owner_id) ;
36
- match ( headers. safety , sig. header . safety ( ) ) {
37
- ( false , Safety :: Unsafe ) => span_lint (
36
+ match ( headers. safety . is_missing ( ) , sig. header . safety ( ) ) {
37
+ ( true , Safety :: Unsafe ) => headers . safety . lint (
38
38
cx,
39
39
MISSING_SAFETY_DOC ,
40
40
span,
41
41
"unsafe function's docs are missing a `# Safety` section" ,
42
42
) ,
43
- ( true , Safety :: Safe ) => span_lint (
43
+ ( false , Safety :: Safe ) => span_lint (
44
44
cx,
45
45
UNNECESSARY_SAFETY_DOC ,
46
46
span,
47
47
"safe function's docs have unnecessary `# Safety` section" ,
48
48
) ,
49
49
_ => ( ) ,
50
50
}
51
- if ! headers. panics
51
+ if headers. panics . is_missing ( )
52
52
&& let Some ( body_id) = body_id
53
53
&& let Some ( panic_span) = find_panic ( cx, body_id)
54
54
{
55
- span_lint_and_note (
55
+ headers . panics . lint_and_then (
56
56
cx,
57
57
MISSING_PANICS_DOC ,
58
58
span,
59
59
"docs for function which may panic missing `# Panics` section" ,
60
- Some ( panic_span) ,
61
- "first possible panic found here" ,
60
+ |diag| {
61
+ diag. span_note ( panic_span, "first possible panic found here" ) ;
62
+ } ,
62
63
) ;
63
64
}
64
- if ! headers. errors {
65
+ if headers. errors . is_missing ( ) {
65
66
if is_type_diagnostic_item ( cx, return_ty ( cx, owner_id) , sym:: Result ) {
66
- span_lint (
67
+ headers . errors . lint (
67
68
cx,
68
69
MISSING_ERRORS_DOC ,
69
70
span,
@@ -85,7 +86,7 @@ pub fn check(
85
86
&& let ty:: Coroutine ( _, subs) = ret_ty. kind ( )
86
87
&& is_type_diagnostic_item ( cx, subs. as_coroutine ( ) . return_ty ( ) , sym:: Result )
87
88
{
88
- span_lint (
89
+ headers . errors . lint (
89
90
cx,
90
91
MISSING_ERRORS_DOC ,
91
92
span,
0 commit comments