From fdc9a649fffa5662571b27bb2353f55dca53277c Mon Sep 17 00:00:00 2001 From: sinkuu Date: Sun, 8 Oct 2017 18:04:45 +0900 Subject: [PATCH] Exclude Fn traits --- clippy_lints/src/needless_pass_by_value.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index a995593e8e5..29598a20f0d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -75,8 +75,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { _ => return, } + // Allow `Borrow` or functions to be taken by value let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT)); - let fn_trait = need!(cx.tcx.lang_items().fn_trait()); + let fn_traits = [ + need!(cx.tcx.lang_items().fn_trait()), + need!(cx.tcx.lang_items().fn_once_trait()), + need!(cx.tcx.lang_items().fn_mut_trait()), + ]; let sized_trait = need!(cx.tcx.lang_items().sized_trait()); @@ -119,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { { // * Exclude a type that is specifically bounded by `Borrow`. // * Exclude a type whose reference also fulfills its bound. - // (e.g. `std::borrow::Borrow`, `serde::Serialize`) + // (e.g. `std::convert::AsRef`, `serde::Serialize`) let (implements_borrow_trait, all_borrowable_trait) = { let preds = preds .iter() @@ -143,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { !is_self(arg), !ty.is_mutable_pointer(), !is_copy(cx, ty), - !implements_trait(cx, ty, fn_trait, &[]), + !fn_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])), !implements_borrow_trait, !all_borrowable_trait,