Skip to content

Commit 1245de1

Browse files
committed
Don't suggest changing explicit Clone impls if they have generics
1 parent 41a710e commit 1245de1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clippy_lints/src/derive.rs

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
148148
return;
149149
}
150150
}
151+
for subst in substs {
152+
if let Some(subst) = subst.as_type() {
153+
if let ty::TyParam(_) = subst.sty {
154+
return;
155+
}
156+
}
157+
}
151158
},
152159
_ => (),
153160
}

tests/ui/clone_on_copy_impl.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::marker::PhantomData;
2+
use std::fmt;
3+
4+
pub struct Key<T> {
5+
#[doc(hidden)]
6+
pub __name: &'static str,
7+
#[doc(hidden)]
8+
pub __phantom: PhantomData<T>,
9+
}
10+
11+
impl<T> Copy for Key<T> {}
12+
13+
impl<T> Clone for Key<T> {
14+
fn clone(&self) -> Self {
15+
Key {
16+
__name: self.__name,
17+
__phantom: self.__phantom,
18+
}
19+
}
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)