diff options
| author | bors <bors@rust-lang.org> | 2020-04-26 20:12:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-26 20:12:48 +0000 |
| commit | e83f7563495dbe2629b0cbc738afb0808c4482e1 (patch) | |
| tree | e6008f7c09e14c44b05015e5ede8c9e8c52c6683 /src/liballoc | |
| parent | 7f3b3df9e2f2efe3434b4f6fc76462d2c8ad332f (diff) | |
| parent | 962cae070f085f7c67813aba6b75547e172ec669 (diff) | |
Auto merge of #71593 - Dylan-DPC:rollup-ms7j94u, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #71421 (Add a function to turn Box<T> into Box<[T]>) - #71537 (Remove support for self-opening) - #71551 (Minor refactoring around IndexVec usage in generator transformation) - #71569 ([miri] Throw UB if target size and data size don't match) - #71576 (check that `AsRef` and `AsMut` are inlined) Failed merges: - #71558 (Cleanup and document `-Z tls-model` ) r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 3d657396a9f..b3a771a721d 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -239,6 +239,16 @@ impl<T> Box<T> { pub fn pin(x: T) -> Pin<Box<T>> { (box x).into() } + + /// Converts a `Box<T>` into a `Box<[T]>` + /// + /// This conversion does not allocate on the heap and happens in place. + /// + #[unstable(feature = "box_into_boxed_slice", issue = "71582")] + pub fn into_boxed_slice(boxed: Box<T>) -> Box<[T]> { + // *mut T and *mut [T; 1] have the same size and alignment + unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [T; 1] as *mut [T]) } + } } impl<T> Box<[T]> { |
