]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/needless_pass_by_value.rs
clippy
[rust.git] / clippy_lints / src / needless_pass_by_value.rs
index ca87deac9891c905913b99430bca8859ae6cfb2a..e39fb23365a27a9cadb3c29d48d619529895f2ee 100644 (file)
@@ -64,11 +64,11 @@ macro_rules! need {
     };
 }
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
+impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
     #[allow(clippy::too_many_lines)]
     fn check_fn(
         &mut self,
-        cx: &LateContext<'a, 'tcx>,
+        cx: &LateContext<'tcx>,
         kind: FnKind<'tcx>,
         decl: &'tcx FnDecl<'_>,
         body: &'tcx Body<'_>,
@@ -100,7 +100,7 @@ fn check_fn(
 
         // Allow `Borrow` or functions to be taken by value
         let borrow_trait = need!(get_trait_def_id(cx, &paths::BORROW_TRAIT));
-        let whitelisted_traits = [
+        let allowed_traits = [
             need!(cx.tcx.lang_items().fn_trait()),
             need!(cx.tcx.lang_items().fn_once_trait()),
             need!(cx.tcx.lang_items().fn_mut_trait()),
@@ -111,15 +111,15 @@ fn check_fn(
 
         let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
 
-        let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter())
+        let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter())
             .filter(|p| !p.is_global())
             .filter_map(|obligation| {
-                if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() {
-                    if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars()
-                    {
+                // Note that we do not want to deal with qualified predicates here.
+                if let ty::PredicateKind::Trait(pred, _) = obligation.predicate.kind() {
+                    if pred.def_id() == sized_trait {
                         return None;
                     }
-                    Some(poly_trait_ref)
+                    Some(pred)
                 } else {
                     None
                 }
@@ -135,7 +135,8 @@ fn check_fn(
         } = {
             let mut ctx = MovedVariablesCtxt::default();
             cx.tcx.infer_ctxt().enter(|infcx| {
-                euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body);
+                euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
+                    .consume_body(body);
             });
             ctx
         };
@@ -158,14 +159,13 @@ fn check_fn(
                 }
             }
 
-            //
             // * Exclude a type that is specifically bounded by `Borrow`.
             // * Exclude a type whose reference also fulfills its bound. (e.g., `std::convert::AsRef`,
             //   `serde::Serialize`)
             let (implements_borrow_trait, all_borrowable_trait) = {
                 let preds = preds
                     .iter()
-                    .filter(|t| t.skip_binder().self_ty() == ty)
+                    .filter(|t| t.self_ty() == ty)
                     .collect::<Vec<_>>();
 
                 (
@@ -173,14 +173,13 @@ fn check_fn(
                     !preds.is_empty() && {
                         let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_root_empty, ty);
                         preds.iter().all(|t| {
-                            let ty_params = &t
-                                .skip_binder()
+                            let ty_params = t
                                 .trait_ref
                                 .substs
                                 .iter()
                                 .skip(1)
                                 .collect::<Vec<_>>();
-                            implements_trait(cx, ty_empty_region, t.def_id(), ty_params)
+                            implements_trait(cx, ty_empty_region, t.def_id(), &ty_params)
                         })
                     },
                 )
@@ -190,7 +189,7 @@ fn check_fn(
                 if !is_self(arg);
                 if !ty.is_mutable_ptr();
                 if !is_copy(cx, ty);
-                if !whitelisted_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
+                if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
                 if !implements_borrow_trait;
                 if !all_borrowable_trait;