Use utils::is_copy instead of hand-rolling it

This commit is contained in:
Oliver Schneider 2017-04-28 17:03:18 +02:00
parent 09c5359b9d
commit 81a55330dc
2 changed files with 4 additions and 9 deletions

View 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 {

View file

@ -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(), &parameter_environment, expr.span) {
if is_copy(cx, ty, parent) {
span_lint_and_then(cx,
CLONE_ON_COPY,
expr.span,