summaryrefslogtreecommitdiffstats
path: root/tests/ui/pin-macro
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/pin-macro
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/pin-macro')
-rw-r--r--tests/ui/pin-macro/cant_access_internals.rs12
-rw-r--r--tests/ui/pin-macro/cant_access_internals.stderr11
-rw-r--r--tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs28
-rw-r--r--tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr31
4 files changed, 82 insertions, 0 deletions
diff --git a/tests/ui/pin-macro/cant_access_internals.rs b/tests/ui/pin-macro/cant_access_internals.rs
new file mode 100644
index 000000000..5826a18b5
--- /dev/null
+++ b/tests/ui/pin-macro/cant_access_internals.rs
@@ -0,0 +1,12 @@
+// edition:2018
+
+use core::{
+ marker::PhantomPinned,
+ mem,
+ pin::{pin, Pin},
+};
+
+fn main() {
+ let mut phantom_pinned = pin!(PhantomPinned);
+ mem::take(phantom_pinned.pointer); //~ ERROR use of unstable library feature 'unsafe_pin_internals'
+}
diff --git a/tests/ui/pin-macro/cant_access_internals.stderr b/tests/ui/pin-macro/cant_access_internals.stderr
new file mode 100644
index 000000000..d43027657
--- /dev/null
+++ b/tests/ui/pin-macro/cant_access_internals.stderr
@@ -0,0 +1,11 @@
+error[E0658]: use of unstable library feature 'unsafe_pin_internals'
+ --> $DIR/cant_access_internals.rs:11:15
+ |
+LL | mem::take(phantom_pinned.pointer);
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(unsafe_pin_internals)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
new file mode 100644
index 000000000..59774bc75
--- /dev/null
+++ b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
@@ -0,0 +1,28 @@
+// edition:2018
+
+use core::{
+ convert::identity,
+ marker::PhantomPinned,
+ mem::drop as stuff,
+ pin::pin,
+};
+
+fn function_call_stops_borrow_extension() {
+ let phantom_pinned = identity(pin!(PhantomPinned));
+ //~^ ERROR temporary value dropped while borrowed
+ stuff(phantom_pinned)
+}
+
+fn promotion_only_works_for_the_innermost_block() {
+ let phantom_pinned = {
+ let phantom_pinned = pin!(PhantomPinned);
+ //~^ ERROR temporary value dropped while borrowed
+ phantom_pinned
+ };
+ stuff(phantom_pinned)
+}
+
+fn main() {
+ function_call_stops_borrow_extension();
+ promotion_only_works_for_the_innermost_block();
+}
diff --git a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
new file mode 100644
index 000000000..4ecc6370d
--- /dev/null
+++ b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
@@ -0,0 +1,31 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/lifetime_errors_on_promotion_misusage.rs:11:35
+ |
+LL | let phantom_pinned = identity(pin!(PhantomPinned));
+ | ^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | |
+ | creates a temporary value which is freed while still in use
+LL |
+LL | stuff(phantom_pinned)
+ | -------------- borrow later used here
+ |
+ = note: consider using a `let` binding to create a longer lived value
+ = note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/lifetime_errors_on_promotion_misusage.rs:18:30
+ |
+LL | let phantom_pinned = {
+ | -------------- borrow later stored here
+LL | let phantom_pinned = pin!(PhantomPinned);
+ | ^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+...
+LL | };
+ | - temporary value is freed at the end of this statement
+ |
+ = note: consider using a `let` binding to create a longer lived value
+ = note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0716`.