Skip to content

Commit 1ca5903

Browse files
committed
Make derive lint handle generics correctly
1 parent 7843f3f commit 1ca5903

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/derive.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc::lint::*;
2+
use rustc::middle::subst::Subst;
23
use rustc::middle::ty::TypeVariants;
34
use rustc::middle::ty::fast_reject::simplify_type;
45
use rustc::middle::ty;
@@ -70,16 +71,17 @@ impl LintPass for Derive {
7071

7172
impl LateLintPass for Derive {
7273
fn check_item(&mut self, cx: &LateContext, item: &Item) {
73-
let ast_ty_to_ty_cache = cx.tcx.ast_ty_to_ty_cache.borrow();
74+
7475

7576
if_let_chain! {[
76-
let ItemImpl(_, _, ref ast_generics, Some(ref trait_ref), ref ast_ty, _) = item.node,
77-
let Some(&ty) = ast_ty_to_ty_cache.get(&ast_ty.id)
77+
let ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node
7878
], {
79+
80+
let ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(item.id)).ty;
7981
if item.attrs.iter().any(is_automatically_derived) {
8082
check_hash_peq(cx, item.span, trait_ref, ty);
8183
}
82-
else if !ast_generics.is_lt_parameterized() {
84+
else {
8385
check_copy_clone(cx, item, trait_ref, ty);
8486
}
8587
}}
@@ -132,8 +134,9 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>,
132134
trait_ref: &TraitRef, ty: ty::Ty<'tcx>) {
133135
if match_path(&trait_ref.path, &CLONE_TRAIT_PATH) {
134136
let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, item.id);
137+
let subst_ty = ty.subst(cx.tcx, &parameter_environment.free_substs);
135138

136-
if ty.moves_by_default(&parameter_environment, item.span) {
139+
if subst_ty.moves_by_default(&parameter_environment, item.span) {
137140
return; // ty is not Copy
138141
}
139142

0 commit comments

Comments
 (0)