2022-01-24 01:41:37 +01:00
|
|
|
// edition:2021
|
2024-06-20 06:06:53 +10:00
|
|
|
|
2022-01-24 01:41:37 +01:00
|
|
|
use core::marker::PhantomPinned;
|
|
|
|
use core::mem::{drop as stuff, transmute};
|
|
|
|
use core::pin::{Pin, pin};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn basic() {
|
|
|
|
let it: Pin<&mut PhantomPinned> = pin!(PhantomPinned);
|
|
|
|
stuff(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn extension_works_through_block() {
|
|
|
|
let it: Pin<&mut PhantomPinned> = { pin!(PhantomPinned) };
|
|
|
|
stuff(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn extension_works_through_unsafe_block() {
|
|
|
|
// "retro-type-inference" works as well.
|
|
|
|
let it: Pin<&mut PhantomPinned> = unsafe { pin!(transmute(())) };
|
|
|
|
stuff(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unsize_coercion() {
|
|
|
|
let slice: Pin<&mut [PhantomPinned]> = pin!([PhantomPinned; 2]);
|
|
|
|
stuff(slice);
|
|
|
|
let dyn_obj: Pin<&mut dyn Send> = pin!([PhantomPinned; 2]);
|
|
|
|
stuff(dyn_obj);
|
|
|
|
}
|
2025-03-28 10:16:03 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rust_2024_expr() {
|
|
|
|
// Check that we accept a Rust 2024 $expr.
|
|
|
|
std::pin::pin!(const { 1 });
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2025-03-27 18:30:51 +01:00
|
|
|
#[cfg(not(bootstrap))]
|
2025-03-28 10:16:03 +01:00
|
|
|
fn temp_lifetime() {
|
|
|
|
// Check that temporary lifetimes work as in Rust 2021.
|
|
|
|
// Regression test for https://github.com/rust-lang/rust/issues/138596
|
|
|
|
match std::pin::pin!(foo(&mut 0)) {
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
async fn foo(_: &mut usize) {}
|
|
|
|
}
|
2025-03-28 10:38:44 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn transitive_extension() {
|
|
|
|
async fn temporary() {}
|
|
|
|
|
|
|
|
// `pin!` witnessed in the wild being used like this, even if it yields
|
|
|
|
// a `Pin<&mut &mut impl Unpin>`; it does work because `pin!`
|
|
|
|
// happens to transitively extend the lifespan of `temporary()`.
|
|
|
|
let p = pin!(&mut temporary());
|
|
|
|
let _use = p;
|
|
|
|
}
|