]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs
Cleanup
[rust.git] / src / tools / clippy / clippy_lints / src / needless_pass_by_value.rs
index 5043b7b1fc3c1858743ee4862127e67aed09a4a0..9306b198051c260d72134d767942cfbd547a9a7c 100644 (file)
@@ -8,7 +8,7 @@
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_hir::intravisit::FnKind;
-use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind};
+use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Impl, Node, PatKind, QPath, TyKind};
 use rustc_infer::infer::TyCtxtInferExt;
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_middle::ty::{self, TypeFoldable};
@@ -92,7 +92,7 @@ fn check_fn(
         if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
             if matches!(
                 item.kind,
-                ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..)
+                ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)
             ) {
                 return;
             }
@@ -115,13 +115,15 @@ fn check_fn(
             .filter(|p| !p.is_global())
             .filter_map(|obligation| {
                 // Note that we do not want to deal with qualified predicates here.
-                if let ty::PredicateKind::Atom(ty::PredicateAtom::Trait(pred, _)) = obligation.predicate.kind() {
-                    if pred.def_id() == sized_trait {
-                        return None;
+                let binder = obligation.predicate.bound_atom();
+                match binder.skip_binder() {
+                    ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
+                        if pred.def_id() == sized_trait {
+                            return None;
+                        }
+                        Some(pred)
                     }
-                    Some(pred)
-                } else {
-                    None
+                    _ => None,
                 }
             })
             .collect::<Vec<_>>();