@@ -3,6 +3,7 @@ use rustc_errors::Diag;
33use rustc_hir as hir;
44use rustc_lint:: { LateContext , LintContext } ;
55use rustc_middle:: ty:: { self , Ty } ;
6+ use rustc_span:: def_id:: DefIdSet ;
67use rustc_span:: { Span , sym} ;
78
89use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_then} ;
@@ -34,22 +35,29 @@ 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 , msrv : Msrv ) {
38+ pub ( super ) fn check_item < ' tcx > (
39+ cx : & LateContext < ' tcx > ,
40+ item : & hir:: Item < ' tcx > ,
41+ large_err_threshold : u64 ,
42+ large_err_ignored : & DefIdSet ,
43+ msrv : Msrv ,
44+ ) {
3845 if let hir:: ItemKind :: Fn { ref sig, .. } = item. kind
3946 && let Some ( ( hir_ty, err_ty) ) = result_err_ty ( cx, sig. decl , item. owner_id . def_id , item. span )
4047 {
4148 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
4249 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
4350 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
4451 }
45- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
52+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
4653 }
4754}
4855
4956pub ( super ) fn check_impl_item < ' tcx > (
5057 cx : & LateContext < ' tcx > ,
5158 item : & hir:: ImplItem < ' tcx > ,
5259 large_err_threshold : u64 ,
60+ large_err_ignored : & DefIdSet ,
5361 msrv : Msrv ,
5462) {
5563 // Don't lint if method is a trait's implementation, we can't do anything about those
@@ -61,14 +69,15 @@ pub(super) fn check_impl_item<'tcx>(
6169 let fn_header_span = item. span . with_hi ( sig. decl . output . span ( ) . hi ( ) ) ;
6270 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
6371 }
64- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
72+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
6573 }
6674}
6775
6876pub ( super ) fn check_trait_item < ' tcx > (
6977 cx : & LateContext < ' tcx > ,
7078 item : & hir:: TraitItem < ' tcx > ,
7179 large_err_threshold : u64 ,
80+ large_err_ignored : & DefIdSet ,
7281 msrv : Msrv ,
7382) {
7483 if let hir:: TraitItemKind :: Fn ( ref sig, _) = item. kind {
@@ -77,7 +86,7 @@ pub(super) fn check_trait_item<'tcx>(
7786 if cx. effective_visibilities . is_exported ( item. owner_id . def_id ) {
7887 check_result_unit_err ( cx, err_ty, fn_header_span, msrv) ;
7988 }
80- check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold) ;
89+ check_result_large_err ( cx, err_ty, hir_ty. span , large_err_threshold, large_err_ignored ) ;
8190 }
8291 }
8392}
@@ -95,7 +104,18 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
95104 }
96105}
97106
98- fn check_result_large_err < ' tcx > ( cx : & LateContext < ' tcx > , err_ty : Ty < ' tcx > , hir_ty_span : Span , large_err_threshold : u64 ) {
107+ fn check_result_large_err < ' tcx > (
108+ cx : & LateContext < ' tcx > ,
109+ err_ty : Ty < ' tcx > ,
110+ hir_ty_span : Span ,
111+ large_err_threshold : u64 ,
112+ large_err_ignored : & DefIdSet ,
113+ ) {
114+ if let ty:: Adt ( adt, _) = err_ty. kind ( )
115+ && large_err_ignored. contains ( & adt. did ( ) )
116+ {
117+ return ;
118+ }
99119 if let ty:: Adt ( adt, subst) = err_ty. kind ( )
100120 && let Some ( local_def_id) = adt. did ( ) . as_local ( )
101121 && let hir:: Node :: Item ( item) = cx. tcx . hir_node_by_def_id ( local_def_id)
0 commit comments