@@ -3,6 +3,7 @@ use rustc_errors::Applicability;
33use rustc_hir:: { def_id:: LocalDefId , FnDecl , FnRetTy , ImplItemKind , Item , ItemKind , Node , TraitItem , TraitItemKind } ;
44use rustc_lint:: { LateContext , LateLintPass } ;
55use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
6+ use rustc_span:: Symbol ;
67
78declare_clippy_lint ! {
89 /// ### What it does
@@ -46,12 +47,17 @@ impl UnnecessaryBoxReturns {
4647 }
4748 }
4849
49- fn check_fn_decl ( & mut self , cx : & LateContext < ' _ > , decl : & FnDecl < ' _ > , def_id : LocalDefId ) {
50+ fn check_fn_item ( & mut self , cx : & LateContext < ' _ > , decl : & FnDecl < ' _ > , def_id : LocalDefId , name : Symbol ) {
5051 // we don't want to tell someone to break an exported function if they ask us not to
5152 if self . avoid_breaking_exported_api && cx. effective_visibilities . is_exported ( def_id) {
5253 return ;
5354 }
5455
56+ // functions which contain the word "box" are exempt from this lint
57+ if name. as_str ( ) . contains ( "box" ) {
58+ return ;
59+ }
60+
5561 let FnRetTy :: Return ( return_ty_hir) = & decl. output else { return } ;
5662
5763 let return_ty = cx
@@ -91,7 +97,7 @@ impl UnnecessaryBoxReturns {
9197impl LateLintPass < ' _ > for UnnecessaryBoxReturns {
9298 fn check_trait_item ( & mut self , cx : & LateContext < ' _ > , item : & TraitItem < ' _ > ) {
9399 let TraitItemKind :: Fn ( signature, _) = & item. kind else { return } ;
94- self . check_fn_decl ( cx, signature. decl , item. owner_id . def_id ) ;
100+ self . check_fn_item ( cx, signature. decl , item. owner_id . def_id , item . ident . name ) ;
95101 }
96102
97103 fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , item : & rustc_hir:: ImplItem < ' _ > ) {
@@ -104,11 +110,11 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
104110 }
105111
106112 let ImplItemKind :: Fn ( signature, ..) = & item. kind else { return } ;
107- self . check_fn_decl ( cx, signature. decl , item. owner_id . def_id ) ;
113+ self . check_fn_item ( cx, signature. decl , item. owner_id . def_id , item . ident . name ) ;
108114 }
109115
110116 fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
111117 let ItemKind :: Fn ( signature, ..) = & item. kind else { return } ;
112- self . check_fn_decl ( cx, signature. decl , item. owner_id . def_id ) ;
118+ self . check_fn_item ( cx, signature. decl , item. owner_id . def_id , item . ident . name ) ;
113119 }
114120}
0 commit comments