@@ -4,6 +4,7 @@ use rustc_errors::Diag;
44use rustc_hir as hir;
55use rustc_lint:: { LateContext , LintContext } ;
66use rustc_middle:: ty:: { self , Ty } ;
7+ use rustc_span:: def_id:: DefIdSet ;
78use rustc_span:: { Span , sym} ;
89
910use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
@@ -35,22 +36,29 @@ fn result_err_ty<'tcx>(
3536 }
3637}
3738
38- pub ( super ) fn check_item < ' tcx > ( cx : & LateContext < ' tcx > , item : & hir:: Item < ' tcx > , large_err_threshold : u64 , msrv : Msrv ) {
39+ pub ( super ) fn check_item < ' tcx > (
40+ cx : & LateContext < ' tcx > ,
41+ item : & hir:: Item < ' tcx > ,
42+ large_err_threshold : u64 ,
43+ large_err_ignored : & DefIdSet ,
44+ msrv : Msrv ,
45+ ) {
3946 if let hir:: ItemKind :: Fn { ref sig, .. } = item. kind
4047 && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
4148 {
4249 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
4350 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
4451 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
4552 }
46- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
53+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
4754 }
4855}
4956
5057pub ( super ) fn check_impl_item < ' tcx > (
5158 cx : & LateContext < ' tcx > ,
5259 item : & hir:: ImplItem < ' tcx > ,
5360 large_err_threshold : u64 ,
61+ large_err_ignored : & DefIdSet ,
5462 msrv : Msrv ,
5563) {
5664 // Don't lint if method is a trait's implementation, we can't do anything about those
@@ -62,14 +70,15 @@ pub(super) fn check_impl_item<'tcx>(
6270 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
6371 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
6472 }
65- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
73+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
6674 }
6775}
6876
6977pub ( super ) fn check_trait_item < ' tcx > (
7078 cx : & LateContext < ' tcx > ,
7179 item : & hir:: TraitItem < ' tcx > ,
7280 large_err_threshold : u64 ,
81+ large_err_ignored : & DefIdSet ,
7382 msrv : Msrv ,
7483) {
7584 if let hir:: TraitItemKind :: Fn ( ref sig, _) = item. kind {
@@ -78,7 +87,7 @@ pub(super) fn check_trait_item<'tcx>(
7887 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
7988 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
8089 }
81- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
90+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
8291 }
8392 }
8493}
@@ -96,7 +105,18 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
96105 }
97106}
98107
99- fn check_result_large_err < ' tcx > ( cx : & LateContext < ' tcx > , err_ty : Ty < ' tcx > , hir_ty_span : Span , large_err_threshold : u64 ) {
108+ fn check_result_large_err < ' tcx > (
109+ cx : & LateContext < ' tcx > ,
110+ err_ty : Ty < ' tcx > ,
111+ hir_ty_span : Span ,
112+ large_err_threshold : u64 ,
113+ large_err_ignored : & DefIdSet ,
114+ ) {
115+ if let ty:: Adt ( adt, _) = err_ty. kind ( )
116+ && large_err_ignored. contains ( & adt. did ( ) )
117+ {
118+ return ;
119+ }
100120 if let ty:: Adt ( adt, subst) = err_ty. kind ( )
101121 && let Some ( local_def_id) = adt. did ( ) . as_local ( )
102122 && let hir:: Node :: Item ( item) = cx. tcx . hir_node_by_def_id ( local_def_id)
0 commit comments