summaryrefslogtreecommitdiffstats
path: root/src/test/ui/pin-macro
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/pin-macro')
-rw-r--r--src/test/ui/pin-macro/cant_access_internals.rs13
-rw-r--r--src/test/ui/pin-macro/cant_access_internals.stderr11
-rw-r--r--src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs29
-rw-r--r--src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr31
4 files changed, 84 insertions, 0 deletions
diff --git a/src/test/ui/pin-macro/cant_access_internals.rs b/src/test/ui/pin-macro/cant_access_internals.rs
new file mode 100644
index 000000000..120d08894
--- /dev/null
+++ b/src/test/ui/pin-macro/cant_access_internals.rs
@@ -0,0 +1,13 @@
+// edition:2018
+#![feature(pin_macro)]
+
+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/src/test/ui/pin-macro/cant_access_internals.stderr b/src/test/ui/pin-macro/cant_access_internals.stderr
new file mode 100644
index 000000000..060c9c48c
--- /dev/null
+++ b/src/test/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:12: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/src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs b/src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
new file mode 100644
index 000000000..ca2b6cf75
--- /dev/null
+++ b/src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
@@ -0,0 +1,29 @@
+// edition:2018
+#![feature(pin_macro)]
+
+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/src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr b/src/test/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
new file mode 100644
index 000000000..4971263af
--- /dev/null
+++ b/src/test/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:12:35
+ |
+LL | let phantom_pinned = identity(pin!(PhantomPinned));
+ | ^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | |
+ | creates a temporary 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:19:30
+ |
+LL | let phantom_pinned = {
+ | -------------- borrow later stored here
+LL | let phantom_pinned = pin!(PhantomPinned);
+ | ^^^^^^^^^^^^^^^^^^^ creates a temporary 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`.