summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /src/tools/clippy/tests/ui/non_canonical_clone_impl.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/non_canonical_clone_impl.rs')
-rw-r--r--src/tools/clippy/tests/ui/non_canonical_clone_impl.rs106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs b/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs
new file mode 100644
index 000000000..3b07dd5ce
--- /dev/null
+++ b/src/tools/clippy/tests/ui/non_canonical_clone_impl.rs
@@ -0,0 +1,106 @@
+#![allow(clippy::clone_on_copy, unused)]
+#![no_main]
+
+// lint
+
+struct A(u32);
+
+impl Clone for A {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl Copy for A {}
+
+// do not lint
+
+struct B(u32);
+
+impl Clone for B {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+impl Copy for B {}
+
+// do not lint derived (clone's implementation is `*self` here anyway)
+
+#[derive(Clone, Copy)]
+struct C(u32);
+
+// do not lint derived (fr this time)
+
+struct D(u32);
+
+#[automatically_derived]
+impl Clone for D {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl Copy for D {}
+
+// do not lint if clone is not manually implemented
+
+struct E(u32);
+
+#[automatically_derived]
+impl Clone for E {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl Copy for E {}
+
+// lint since clone is not derived
+
+#[derive(Copy)]
+struct F(u32);
+
+impl Clone for F {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+// do not lint since copy has more restrictive bounds
+
+#[derive(Eq, PartialEq)]
+struct Uwu<A: Copy>(A);
+
+impl<A: Copy> Clone for Uwu<A> {
+ fn clone(&self) -> Self {
+ Self(self.0)
+ }
+
+ fn clone_from(&mut self, source: &Self) {
+ source.clone();
+ *self = source.clone();
+ }
+}
+
+impl<A: std::fmt::Debug + Copy + Clone> Copy for Uwu<A> {}