1+ use clippy_utils:: msrvs:: { self , Msrv } ;
12use rustc_errors:: Diag ;
23use rustc_hir as hir;
34use rustc_lint:: { LateContext , LintContext } ;
@@ -6,8 +7,8 @@ use rustc_middle::ty::{self, Ty};
67use rustc_span:: { Span , sym} ;
78
89use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
9- use clippy_utils:: trait_ref_of_method;
1010use clippy_utils:: ty:: { AdtVariantInfo , approx_ty_size, is_type_diagnostic_item} ;
11+ use clippy_utils:: { is_no_std_crate, trait_ref_of_method} ;
1112
1213use super :: { RESULT_LARGE_ERR , RESULT_UNIT_ERR } ;
1314
@@ -34,46 +35,56 @@ fn result_err_ty<'tcx>(
3435 }
3536}
3637
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 ) {
3839 if let hir:: ItemKind :: Fn ( ref sig, _generics, _) = item. kind
3940 && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
4041 {
4142 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
4243 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 ) ;
4445 }
4546 check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
4647 }
4748}
4849
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+ ) {
5056 // Don't lint if method is a trait's implementation, we can't do anything about those
5157 if let hir:: ImplItemKind :: Fn ( ref sig, _) = item. kind
5258 && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
5359 && trait_ref_of_method ( cx, item. owner_id . def_id ) . is_none ( )
5460 {
5561 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
5662 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 ) ;
5864 }
5965 check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
6066 }
6167}
6268
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+ ) {
6475 if let hir:: TraitItemKind :: Fn ( ref sig, _) = item. kind {
6576 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
6677 if let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span ) {
6778 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 ) ;
6980 }
7081 check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
7182 }
7283 }
7384}
7485
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 ) ) {
7788 span_lint_and_help (
7889 cx,
7990 RESULT_UNIT_ERR ,
0 commit comments