@@ -75,8 +75,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
75
75
_ => return ,
76
76
}
77
77
78
+ // Allow `Borrow` or functions to be taken by value
78
79
let borrow_trait = need ! ( get_trait_def_id( cx, & paths:: BORROW_TRAIT ) ) ;
79
- let fn_trait = need ! ( cx. tcx. lang_items( ) . fn_trait( ) ) ;
80
+ let fn_traits = [
81
+ need ! ( cx. tcx. lang_items( ) . fn_trait( ) ) ,
82
+ need ! ( cx. tcx. lang_items( ) . fn_once_trait( ) ) ,
83
+ need ! ( cx. tcx. lang_items( ) . fn_mut_trait( ) ) ,
84
+ ] ;
80
85
81
86
let sized_trait = need ! ( cx. tcx. lang_items( ) . sized_trait( ) ) ;
82
87
@@ -119,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
119
124
{
120
125
// * Exclude a type that is specifically bounded by `Borrow`.
121
126
// * Exclude a type whose reference also fulfills its bound.
122
- // (e.g. `std::borrow::Borrow `, `serde::Serialize`)
127
+ // (e.g. `std::convert::AsRef `, `serde::Serialize`)
123
128
let ( implements_borrow_trait, all_borrowable_trait) = {
124
129
let preds = preds
125
130
. iter ( )
@@ -143,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
143
148
!is_self( arg) ,
144
149
!ty. is_mutable_pointer( ) ,
145
150
!is_copy( cx, ty) ,
146
- !implements_trait( cx, ty, fn_trait , & [ ] ) ,
151
+ !fn_traits . iter ( ) . any ( | & t| implements_trait( cx, ty, t , & [ ] ) ) ,
147
152
!implements_borrow_trait,
148
153
!all_borrowable_trait,
149
154
0 commit comments