summaryrefslogtreecommitdiffstats
path: root/library/core/tests/pin_macro.rs
blob: 79c8c166c58d9d8381ffb7cbbce5a1edeea987c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// edition:2021
use core::{
    marker::PhantomPinned,
    mem::{drop as stuff, transmute},
    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);
}