-#![feature(untagged_unions)]
#![allow(dead_code)]
#![warn(clippy::expl_impl_clone_on_copy)]
-use std::hash::{Hash, Hasher};
-
-#[derive(PartialEq, Hash)]
-struct Foo;
-
-impl PartialEq<u64> for Foo {
- fn eq(&self, _: &u64) -> bool {
- true
- }
-}
-
-#[derive(Hash)]
-struct Bar;
-
-impl PartialEq for Bar {
- fn eq(&self, _: &Bar) -> bool {
- true
- }
-}
-
-#[derive(Hash)]
-struct Baz;
-
-impl PartialEq<Baz> for Baz {
- fn eq(&self, _: &Baz) -> bool {
- true
- }
-}
-
-#[derive(PartialEq)]
-struct Bah;
-
-impl Hash for Bah {
- fn hash<H: Hasher>(&self, _: &mut H) {}
-}
-
#[derive(Copy)]
struct Qux;
}
}
-// Ok, `Clone` cannot be derived because of the big array
#[derive(Copy)]
struct BigArray {
a: [u8; 65],
}
}
-// Ok, function pointers are not always Clone
#[derive(Copy)]
struct FnPtr {
a: fn() -> !,
}
}
-// Ok, generics
+// Ok, Clone trait impl doesn't have constrained generics.
#[derive(Copy)]
struct Generic<T> {
a: T,
}
}
+#[derive(Copy)]
+struct Generic2<T>(T);
+impl<T: Clone> Clone for Generic2<T> {
+ fn clone(&self) -> Self {
+ Self(self.0.clone())
+ }
+}
+
+// Ok, Clone trait impl doesn't have constrained generics.
+#[derive(Copy)]
+struct GenericRef<'a, T, U>(T, &'a U);
+impl<T: Clone, U> Clone for GenericRef<'_, T, U> {
+ fn clone(&self) -> Self {
+ Self(self.0.clone(), self.1)
+ }
+}
+
fn main() {}