forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#76655 - CDirkx:const-pin, r=ecstatic-morse
Make some methods of `Pin` unstable const Make the following methods unstable const under the `const_pin` feature: - `new` - `new_unchecked` - `into_inner` - `into_inner_unchecked` - `get_ref` - `into_ref` - `get_mut` - `get_unchecked_mut` Of these, `into_inner` and `into_inner_unchecked` require the unstable `const_precise_live_drops`. Also adds tests for these methods in a const context. Tracking issue: rust-lang#76654 r? @ecstatic-morse
- Loading branch information
Showing
4 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use core::pin::Pin; | ||
|
||
#[test] | ||
fn pin_const() { | ||
// test that the methods of `Pin` are usable in a const context | ||
|
||
const POINTER: &'static usize = &2; | ||
|
||
const PINNED: Pin<&'static usize> = Pin::new(POINTER); | ||
const PINNED_UNCHECKED: Pin<&'static usize> = unsafe { Pin::new_unchecked(POINTER) }; | ||
assert_eq!(PINNED_UNCHECKED, PINNED); | ||
|
||
const INNER: &'static usize = Pin::into_inner(PINNED); | ||
assert_eq!(INNER, POINTER); | ||
|
||
const INNER_UNCHECKED: &'static usize = unsafe { Pin::into_inner_unchecked(PINNED) }; | ||
assert_eq!(INNER_UNCHECKED, POINTER); | ||
|
||
const REF: &'static usize = PINNED.get_ref(); | ||
assert_eq!(REF, POINTER); | ||
|
||
// Note: `pin_mut_const` tests that the methods of `Pin<&mut T>` are usable in a const context. | ||
// A const fn is used because `&mut` is not (yet) usable in constants. | ||
const fn pin_mut_const() { | ||
let _ = Pin::new(&mut 2).into_ref(); | ||
let _ = Pin::new(&mut 2).get_mut(); | ||
let _ = unsafe { Pin::new(&mut 2).get_unchecked_mut() }; | ||
} | ||
|
||
pin_mut_const(); | ||
} |