about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMax Niederman <max@maxniederman.com>2023-11-18 21:01:02 -0800
committerMax Niederman <max@maxniederman.com>2023-11-18 21:01:02 -0800
commitc5ed7b0ead27a9b666c2c4fc14160fba972df793 (patch)
tree55ab28321a510a5995a4276cc4a7c5818136f75e
parent173b95031166abc96bd979360274abe8b5016fde (diff)
downloadrust-c5ed7b0ead27a9b666c2c4fc14160fba972df793.tar.gz
rust-c5ed7b0ead27a9b666c2c4fc14160fba972df793.zip
add test for pinned `must_use` pointers
-rw-r--r--tests/ui/lint/unused/must_use-pin.rs45
-rw-r--r--tests/ui/lint/unused/must_use-pin.stderr20
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/lint/unused/must_use-pin.rs b/tests/ui/lint/unused/must_use-pin.rs
new file mode 100644
index 00000000000..b08515428b1
--- /dev/null
+++ b/tests/ui/lint/unused/must_use-pin.rs
@@ -0,0 +1,45 @@
+#![deny(unused_must_use)]
+
+use std::{ops::Deref, pin::Pin};
+
+#[must_use]
+struct MustUse;
+
+#[must_use]
+struct MustUsePtr<'a, T>(&'a T);
+
+impl<'a, T> Deref for MustUsePtr<'a, T> {
+    type Target = T;
+
+    fn deref(&self) -> &Self::Target {
+        self.0
+    }
+}
+
+fn pin_ref() -> Pin<&'static ()> {
+    Pin::new(&())
+}
+
+fn pin_ref_mut() -> Pin<&'static mut ()> {
+    Pin::new(unimplemented!())
+}
+
+fn pin_must_use_ptr() -> Pin<MustUsePtr<'static, ()>> {
+    Pin::new(MustUsePtr(&()))
+}
+
+fn pin_box() -> Pin<Box<()>> {
+    Box::pin(())
+}
+
+fn pin_box_must_use() -> Pin<Box<MustUse>> {
+    Box::pin(MustUse)
+}
+
+fn main() {
+    pin_ref();
+    pin_ref_mut();
+    pin_must_use_ptr(); //~ ERROR unused pinned `MustUsePtr` that must be used
+    pin_box();
+    pin_box_must_use(); //~ ERROR unused pinned boxed `MustUse` that must be used
+}
diff --git a/tests/ui/lint/unused/must_use-pin.stderr b/tests/ui/lint/unused/must_use-pin.stderr
new file mode 100644
index 00000000000..c04f8fef487
--- /dev/null
+++ b/tests/ui/lint/unused/must_use-pin.stderr
@@ -0,0 +1,20 @@
+error: unused pinned `MustUsePtr` that must be used
+  --> $DIR/must_use-pin.rs:42:5
+   |
+LL |     pin_must_use_ptr();
+   |     ^^^^^^^^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/must_use-pin.rs:1:9
+   |
+LL | #![deny(unused_must_use)]
+   |         ^^^^^^^^^^^^^^^
+
+error: unused pinned boxed `MustUse` that must be used
+  --> $DIR/must_use-pin.rs:44:5
+   |
+LL |     pin_box_must_use();
+   |     ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+