@@ -3,6 +3,7 @@ use rustc_errors::Applicability;
3
3
use rustc_hir:: { def_id:: LocalDefId , FnDecl , FnRetTy , ImplItemKind , Item , ItemKind , Node , TraitItem , TraitItemKind } ;
4
4
use rustc_lint:: { LateContext , LateLintPass } ;
5
5
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
6
+ use rustc_span:: Symbol ;
6
7
7
8
declare_clippy_lint ! {
8
9
/// ### What it does
@@ -46,12 +47,17 @@ impl UnnecessaryBoxReturns {
46
47
}
47
48
}
48
49
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 ) {
50
51
// we don't want to tell someone to break an exported function if they ask us not to
51
52
if self . avoid_breaking_exported_api && cx. effective_visibilities . is_exported ( def_id) {
52
53
return ;
53
54
}
54
55
56
+ // functions which contain the word "box" are exempt from this lint
57
+ if name. as_str ( ) . contains ( "box" ) {
58
+ return ;
59
+ }
60
+
55
61
let FnRetTy :: Return ( return_ty_hir) = & decl. output else { return } ;
56
62
57
63
let return_ty = cx
@@ -91,7 +97,7 @@ impl UnnecessaryBoxReturns {
91
97
impl LateLintPass < ' _ > for UnnecessaryBoxReturns {
92
98
fn check_trait_item ( & mut self , cx : & LateContext < ' _ > , item : & TraitItem < ' _ > ) {
93
99
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 ) ;
95
101
}
96
102
97
103
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , item : & rustc_hir:: ImplItem < ' _ > ) {
@@ -104,11 +110,11 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
104
110
}
105
111
106
112
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 ) ;
108
114
}
109
115
110
116
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
111
117
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 ) ;
113
119
}
114
120
}
0 commit comments