]> git.lizzy.rs Git - rust.git/commitdiff
Don't suggest changing explicit Clone impls if they have generics
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 11 Jan 2018 09:28:42 +0000 (10:28 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 11 Jan 2018 09:28:42 +0000 (10:28 +0100)
clippy_lints/src/derive.rs
tests/ui/clone_on_copy_impl.rs [new file with mode: 0644]

index 6ce67a9b05c662f8c2ca56d4709e41c6302586b8..d327d0570f1aebcc685707f0a5e2dd3ba5064c2e 100644 (file)
@@ -148,6 +148,13 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
                         return;
                     }
                 }
+                for subst in substs {
+                    if let Some(subst) = subst.as_type() {
+                        if let ty::TyParam(_) = subst.sty {
+                            return;
+                        }
+                    }
+                }
             },
             _ => (),
         }
diff --git a/tests/ui/clone_on_copy_impl.rs b/tests/ui/clone_on_copy_impl.rs
new file mode 100644 (file)
index 0000000..e214416
--- /dev/null
@@ -0,0 +1,22 @@
+use std::marker::PhantomData;
+use std::fmt;
+
+pub struct Key<T> {
+    #[doc(hidden)]
+    pub __name: &'static str,
+    #[doc(hidden)]
+    pub __phantom: PhantomData<T>,
+}
+
+impl<T> Copy for Key<T> {}
+
+impl<T> Clone for Key<T> {
+    fn clone(&self) -> Self {
+        Key {
+            __name: self.__name,
+            __phantom: self.__phantom,
+        }
+    }
+}
+
+fn main() {}