|
1 | 1 | use rustc::lint::*;
|
| 2 | +use rustc::middle::ty::TypeVariants; |
2 | 3 | use rustc::middle::ty::fast_reject::simplify_type;
|
3 | 4 | use rustc::middle::ty;
|
4 | 5 | use rustc_front::hir::*;
|
5 | 6 | use syntax::ast::{Attribute, MetaItemKind};
|
6 | 7 | use syntax::codemap::Span;
|
7 | 8 | use utils::{CLONE_TRAIT_PATH, HASH_PATH};
|
8 | 9 | use utils::{match_path, span_lint_and_then};
|
9 |
| -use rustc::middle::ty::TypeVariants; |
10 | 10 |
|
11 | 11 | /// **What it does:** This lint warns about deriving `Hash` but implementing `PartialEq`
|
12 | 12 | /// explicitly.
|
@@ -73,14 +73,14 @@ impl LateLintPass for Derive {
|
73 | 73 | let ast_ty_to_ty_cache = cx.tcx.ast_ty_to_ty_cache.borrow();
|
74 | 74 |
|
75 | 75 | if_let_chain! {[
|
76 |
| - let ItemImpl(_, _, _, Some(ref trait_ref), ref ast_ty, _) = item.node, |
| 76 | + let ItemImpl(_, _, ref ast_generics, Some(ref trait_ref), ref ast_ty, _) = item.node, |
77 | 77 | let Some(&ty) = ast_ty_to_ty_cache.get(&ast_ty.id)
|
78 | 78 | ], {
|
79 | 79 | if item.attrs.iter().any(is_automatically_derived) {
|
80 | 80 | check_hash_peq(cx, item.span, trait_ref, ty);
|
81 | 81 | }
|
82 |
| - else { |
83 |
| - check_copy_clone(cx, item.span, trait_ref, ty); |
| 82 | + else if !ast_generics.is_lt_parameterized() { |
| 83 | + check_copy_clone(cx, item, trait_ref, ty); |
84 | 84 | }
|
85 | 85 | }}
|
86 | 86 | }
|
@@ -127,11 +127,13 @@ fn check_hash_peq(cx: &LateContext, span: Span, trait_ref: &TraitRef, ty: ty::Ty
|
127 | 127 | }
|
128 | 128 |
|
129 | 129 | /// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
|
130 |
| -fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref: &TraitRef, ty: ty::Ty<'tcx>) { |
| 130 | +fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, |
| 131 | + item: &Item, |
| 132 | + trait_ref: &TraitRef, ty: ty::Ty<'tcx>) { |
131 | 133 | if match_path(&trait_ref.path, &CLONE_TRAIT_PATH) {
|
132 |
| - let parameter_environment = cx.tcx.empty_parameter_environment(); |
| 134 | + let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, item.id); |
133 | 135 |
|
134 |
| - if ty.moves_by_default(¶meter_environment, span) { |
| 136 | + if ty.moves_by_default(¶meter_environment, item.span) { |
135 | 137 | return; // ty is not Copy
|
136 | 138 | }
|
137 | 139 |
|
@@ -160,10 +162,10 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref:
|
160 | 162 |
|
161 | 163 | span_lint_and_then(cx,
|
162 | 164 | DERIVE_HASH_NOT_EQ,
|
163 |
| - span, |
| 165 | + item.span, |
164 | 166 | "you are implementing `Clone` explicitly on a `Copy` type",
|
165 | 167 | |db| {
|
166 |
| - db.span_note(span, "consider deriving `Clone` or removing `Copy`"); |
| 168 | + db.span_note(item.span, "consider deriving `Clone` or removing `Copy`"); |
167 | 169 | });
|
168 | 170 | }
|
169 | 171 | }
|
|
0 commit comments