]> git.lizzy.rs Git - rust.git/blob - library/core/tests/pin_macro.rs
Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors
[rust.git] / library / core / tests / pin_macro.rs
1 // edition:2021
2 use core::{
3     marker::PhantomPinned,
4     mem::{drop as stuff, transmute},
5     pin::{pin, Pin},
6 };
7
8 #[test]
9 fn basic() {
10     let it: Pin<&mut PhantomPinned> = pin!(PhantomPinned);
11     stuff(it);
12 }
13
14 #[test]
15 fn extension_works_through_block() {
16     let it: Pin<&mut PhantomPinned> = { pin!(PhantomPinned) };
17     stuff(it);
18 }
19
20 #[test]
21 fn extension_works_through_unsafe_block() {
22     // "retro-type-inference" works as well.
23     let it: Pin<&mut PhantomPinned> = unsafe { pin!(transmute(())) };
24     stuff(it);
25 }
26
27 #[test]
28 fn unsize_coercion() {
29     let slice: Pin<&mut [PhantomPinned]> = pin!([PhantomPinned; 2]);
30     stuff(slice);
31     let dyn_obj: Pin<&mut dyn Send> = pin!([PhantomPinned; 2]);
32     stuff(dyn_obj);
33 }