]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/derive.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / derive.rs
index b7a672cd80aaafdc578ccc0f8d48cf5aefb85fab..c629c0e535377ebf1b2e05ccd96c2a62fb8923dc 100644 (file)
@@ -1,43 +1,6 @@
-#![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;
 
@@ -71,7 +34,6 @@ fn clone(&self) -> Self {
     }
 }
 
-// Ok, `Clone` cannot be derived because of the big array
 #[derive(Copy)]
 struct BigArray {
     a: [u8; 65],
@@ -83,7 +45,6 @@ fn clone(&self) -> Self {
     }
 }
 
-// Ok, function pointers are not always Clone
 #[derive(Copy)]
 struct FnPtr {
     a: fn() -> !,
@@ -95,7 +56,7 @@ fn clone(&self) -> Self {
     }
 }
 
-// Ok, generics
+// Ok, Clone trait impl doesn't have constrained generics.
 #[derive(Copy)]
 struct Generic<T> {
     a: T,
@@ -107,4 +68,21 @@ fn clone(&self) -> Self {
     }
 }
 
+#[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() {}