Skip to content

Commit 55a80a3

Browse files
Write {ui,} tests for pin_macro and pin!
1 parent 5ccb429 commit 55a80a3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

core/tests/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#![feature(inline_const)]
4646
#![feature(is_sorted)]
4747
#![feature(pattern)]
48+
#![feature(pin_macro)]
4849
#![feature(sort_internals)]
4950
#![feature(slice_take)]
5051
#![feature(maybe_uninit_uninit_array)]
@@ -122,6 +123,7 @@ mod ops;
122123
mod option;
123124
mod pattern;
124125
mod pin;
126+
mod pin_macro;
125127
mod ptr;
126128
mod result;
127129
mod simd;

core/tests/pin_macro.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)