about summary refs log tree commit diff
path: root/src/test/ui/drop
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-07-21 22:00:15 +0000
committerMichael Goulet <michael@errs.io>2022-08-16 00:59:06 +0000
commitfd934c99bcf1a930ef44a27129ef24b323d3c54f (patch)
treed9b3906d9c0b43f00807efc1cc7563e259893011 /src/test/ui/drop
parent40336865fe7d4a01139a3336639c6971647e885c (diff)
downloadrust-fd934c99bcf1a930ef44a27129ef24b323d3c54f.tar.gz
rust-fd934c99bcf1a930ef44a27129ef24b323d3c54f.zip
Do not allow Drop impl on foreign fundamental types
Diffstat (limited to 'src/test/ui/drop')
-rw-r--r--src/test/ui/drop/drop-foreign-fundamental.rs23
-rw-r--r--src/test/ui/drop/drop-foreign-fundamental.stderr9
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/ui/drop/drop-foreign-fundamental.rs b/src/test/ui/drop/drop-foreign-fundamental.rs
new file mode 100644
index 00000000000..c43df40d6c2
--- /dev/null
+++ b/src/test/ui/drop/drop-foreign-fundamental.rs
@@ -0,0 +1,23 @@
+use std::ops::Deref;
+use std::pin::Pin;
+
+struct Whatever<T>(T);
+
+impl<T> Deref for Whatever<T> {
+    type Target = T;
+
+    fn deref(&self) -> &T {
+        &self.0
+    }
+}
+
+struct A;
+
+impl Drop for Pin<Whatever<A>> {
+    //~^ ERROR  the `Drop` trait may only be implemented for local structs, enums, and unions
+    fn drop(&mut self) {}
+}
+
+fn main() {
+    let x = Pin::new(Whatever(1.0f32));
+}
diff --git a/src/test/ui/drop/drop-foreign-fundamental.stderr b/src/test/ui/drop/drop-foreign-fundamental.stderr
new file mode 100644
index 00000000000..fbd1ba08591
--- /dev/null
+++ b/src/test/ui/drop/drop-foreign-fundamental.stderr
@@ -0,0 +1,9 @@
+error[E0120]: the `Drop` trait may only be implemented for local structs, enums, and unions
+  --> $DIR/drop-foreign-fundamental.rs:16:15
+   |
+LL | impl Drop for Pin<Whatever<A>> {
+   |               ^^^^^^^^^^^^^^^^ must be a struct, enum, or union in the current crate
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0120`.