]> git.lizzy.rs Git - rust.git/commitdiff
Use `utils::is_copy` instead of hand-rolling it
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 28 Apr 2017 15:03:18 +0000 (17:03 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 28 Apr 2017 15:03:18 +0000 (17:03 +0200)
clippy_lints/src/derive.rs
clippy_lints/src/methods.rs

index dc1747fd3eb72b5fa587dc8ba01ecf26be650d74..1710871a31f7244eabb4658f66fa96d07335ecff 100644 (file)
@@ -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(), &parameter_environment, item.span) {
-            return; // ty is not Copy
+        if !is_copy(cx, ty, item.id) {
+            return;
         }
 
         match ty.sty {
index 7e1acd8b673163b14182f842f292676fc82d88d8..64a8f72ea0167c48328e5c0d79623ffc130c5b05 100644 (file)
@@ -821,7 +821,6 @@ fn check_general_case(
 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(), &parameter_environment, expr.span) {
+    if is_copy(cx, ty, parent) {
         span_lint_and_then(cx,
                            CLONE_ON_COPY,
                            expr.span,