From 81a55330dccab9e512c446c751e83452e8f86801 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 28 Apr 2017 17:03:18 +0200 Subject: [PATCH] Use `utils::is_copy` instead of hand-rolling it --- clippy_lints/src/derive.rs | 10 +++------- clippy_lints/src/methods.rs | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index dc1747fd3eb7..1710871a31f7 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -1,11 +1,10 @@ use rustc::lint::*; -use rustc::ty::subst::Subst; use rustc::ty::TypeVariants; use rustc::ty; use rustc::hir::*; use syntax::codemap::Span; use utils::paths; -use utils::{is_automatically_derived, span_lint_and_then, match_path_old}; +use utils::{is_automatically_derived, span_lint_and_then, match_path_old, is_copy}; /// **What it does:** Checks for deriving `Hash` but implementing `PartialEq` /// explicitly. @@ -137,11 +136,8 @@ fn check_hash_peq<'a, 'tcx>( /// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint. fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: ty::Ty<'tcx>) { if match_path_old(&trait_ref.path, &paths::CLONE_TRAIT) { - let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, item.id); - let subst_ty = ty.subst(cx.tcx, parameter_environment.free_substs); - - if subst_ty.moves_by_default(cx.tcx.global_tcx(), ¶meter_environment, item.span) { - return; // ty is not Copy + if !is_copy(cx, ty, item.id) { + return; } match ty.sty { diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 7e1acd8b6731..64a8f72ea016 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -821,7 +821,6 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir: fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: ty::Ty) { let ty = cx.tables.expr_ty(expr); let parent = cx.tcx.hir.get_parent(expr.id); - let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, parent); if let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = arg_ty.sty { if let ty::TyRef(..) = inner.sty { span_lint_and_then(cx, @@ -838,7 +837,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t } } - if !ty.moves_by_default(cx.tcx.global_tcx(), ¶meter_environment, expr.span) { + if is_copy(cx, ty, parent) { span_lint_and_then(cx, CLONE_ON_COPY, expr.span,