about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/borrowck/copy-overflow.rs16
-rw-r--r--tests/ui/borrowck/copy-overflow.stderr15
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/borrowck/copy-overflow.rs b/tests/ui/borrowck/copy-overflow.rs
new file mode 100644
index 00000000000..5aa1afdee68
--- /dev/null
+++ b/tests/ui/borrowck/copy-overflow.rs
@@ -0,0 +1,16 @@
+// Regression test for <https://github.com/rust-lang/rust/issues/144165>.
+
+// We were previously suppressing the copy error in the `Clone` impl because we assumed
+// that the only way we get `Copy` ambiguity errors was due to incoherent impls. This is
+// not true, since ambiguities can be encountered due to overflows (among other ways).
+
+struct S<T: 'static>(Option<&'static T>);
+
+impl<T: 'static> Copy for S<T> where S<T>: Copy + Clone {}
+impl<T: 'static> Clone for S<T> {
+    fn clone(&self) -> Self {
+        *self
+        //~^ ERROR cannot move out of `*self` which is behind a shared reference
+    }
+}
+fn main() {}
diff --git a/tests/ui/borrowck/copy-overflow.stderr b/tests/ui/borrowck/copy-overflow.stderr
new file mode 100644
index 00000000000..3f601276f8f
--- /dev/null
+++ b/tests/ui/borrowck/copy-overflow.stderr
@@ -0,0 +1,15 @@
+error[E0507]: cannot move out of `*self` which is behind a shared reference
+  --> $DIR/copy-overflow.rs:12:9
+   |
+LL |         *self
+   |         ^^^^^ move occurs because `*self` has type `S<T>`, which does not implement the `Copy` trait
+   |
+help: consider cloning the value if the performance cost is acceptable
+   |
+LL -         *self
+LL +         self.clone()
+   |
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0507`.