Skip to content

Commit fdc9a64

Browse files
committed
Exclude Fn traits
1 parent 2be6245 commit fdc9a64

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
7575
_ => return,
7676
}
7777

78+
// Allow `Borrow` or functions to be taken by value
7879
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+
];
8085

8186
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
8287

@@ -119,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
119124
{
120125
// * Exclude a type that is specifically bounded by `Borrow`.
121126
// * 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`)
123128
let (implements_borrow_trait, all_borrowable_trait) = {
124129
let preds = preds
125130
.iter()
@@ -143,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
143148
!is_self(arg),
144149
!ty.is_mutable_pointer(),
145150
!is_copy(cx, ty),
146-
!implements_trait(cx, ty, fn_trait, &[]),
151+
!fn_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])),
147152
!implements_borrow_trait,
148153
!all_borrowable_trait,
149154

0 commit comments

Comments
 (0)