1
+ use clippy_utils:: msrvs:: { self , Msrv } ;
1
2
use rustc_errors:: Diag ;
2
3
use rustc_hir as hir;
3
4
use rustc_lint:: { LateContext , LintContext } ;
@@ -6,8 +7,8 @@ use rustc_middle::ty::{self, Ty};
6
7
use rustc_span:: { Span , sym} ;
7
8
8
9
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
9
- use clippy_utils:: trait_ref_of_method;
10
10
use clippy_utils:: ty:: { AdtVariantInfo , approx_ty_size, is_type_diagnostic_item} ;
11
+ use clippy_utils:: { is_no_std_crate, trait_ref_of_method} ;
11
12
12
13
use super :: { RESULT_LARGE_ERR , RESULT_UNIT_ERR } ;
13
14
@@ -34,46 +35,56 @@ fn result_err_ty<'tcx>(
34
35
}
35
36
}
36
37
37
- pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: Item < ' tcx > , large_err_threshold : u64 ) {
38
+ pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: Item < ' tcx > , large_err_threshold : u64 , msrv : & Msrv ) {
38
39
if let hir:: ItemKind :: Fn ( ref sig, _generics, _) = item. kind
39
40
&& let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
40
41
{
41
42
if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
42
43
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
43
- check_result_unit_err ( cx, err_ty, fn_header_span) ;
44
+ check_result_unit_err ( cx, err_ty, fn_header_span, msrv ) ;
44
45
}
45
46
check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
46
47
}
47
48
}
48
49
49
- pub ( super ) fn check_impl_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: ImplItem < ' tcx > , large_err_threshold : u64 ) {
50
+ pub ( super ) fn check_impl_item < ' tcx > (
51
+ cx : & LateContext < ' tcx > ,
52
+ item : & hir:: ImplItem < ' tcx > ,
53
+ large_err_threshold : u64 ,
54
+ msrv : & Msrv ,
55
+ ) {
50
56
// Don't lint if method is a trait's implementation, we can't do anything about those
51
57
if let hir:: ImplItemKind :: Fn ( ref sig, _) = item. kind
52
58
&& let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
53
59
&& trait_ref_of_method ( cx, item. owner_id . def_id ) . is_none ( )
54
60
{
55
61
if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
56
62
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
57
- check_result_unit_err ( cx, err_ty, fn_header_span) ;
63
+ check_result_unit_err ( cx, err_ty, fn_header_span, msrv ) ;
58
64
}
59
65
check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
60
66
}
61
67
}
62
68
63
- pub ( super ) fn check_trait_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: TraitItem < ' tcx > , large_err_threshold : u64 ) {
69
+ pub ( super ) fn check_trait_item < ' tcx > (
70
+ cx : & LateContext < ' tcx > ,
71
+ item : & hir:: TraitItem < ' tcx > ,
72
+ large_err_threshold : u64 ,
73
+ msrv : & Msrv ,
74
+ ) {
64
75
if let hir:: TraitItemKind :: Fn ( ref sig, _) = item. kind {
65
76
let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
66
77
if let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span ) {
67
78
if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
68
- check_result_unit_err ( cx, err_ty, fn_header_span) ;
79
+ check_result_unit_err ( cx, err_ty, fn_header_span, msrv ) ;
69
80
}
70
81
check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
71
82
}
72
83
}
73
84
}
74
85
75
- fn check_result_unit_err ( cx : & LateContext < ' _ > , err_ty : Ty < ' _ > , fn_header_span : Span ) {
76
- if err_ty. is_unit ( ) {
86
+ fn check_result_unit_err ( cx : & LateContext < ' _ > , err_ty : Ty < ' _ > , fn_header_span : Span , msrv : & Msrv ) {
87
+ if err_ty. is_unit ( ) && ( ! is_no_std_crate ( cx ) || msrv . meets ( msrvs :: ERROR_IN_CORE ) ) {
77
88
span_lint_and_help (
78
89
cx,
79
90
RESULT_UNIT_ERR ,
0 commit comments