]> git.proxmox.com Git - rustc.git/blob - library/core/tests/pin.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / library / core / tests / pin.rs
1 use core::pin::Pin;
2
3 #[test]
4 fn pin_const() {
5 // test that the methods of `Pin` are usable in a const context
6
7 const POINTER: &'static usize = &2;
8
9 const PINNED: Pin<&'static usize> = Pin::new(POINTER);
10 const PINNED_UNCHECKED: Pin<&'static usize> = unsafe { Pin::new_unchecked(POINTER) };
11 assert_eq!(PINNED_UNCHECKED, PINNED);
12
13 const INNER: &'static usize = Pin::into_inner(PINNED);
14 assert_eq!(INNER, POINTER);
15
16 const INNER_UNCHECKED: &'static usize = unsafe { Pin::into_inner_unchecked(PINNED) };
17 assert_eq!(INNER_UNCHECKED, POINTER);
18
19 const REF: &'static usize = PINNED.get_ref();
20 assert_eq!(REF, POINTER);
21
22 // Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context.
23 // A const fn is used because `&mut` is not (yet) usable in constants.
24 const fn pin_mut_const() {
25 let _ = Pin::new(&mut 2).into_ref();
26 let _ = Pin::new(&mut 2).get_mut();
27 let _ = unsafe { Pin::new(&mut 2).get_unchecked_mut() };
28 }
29
30 pin_mut_const();
31 }