diff options
| author | bors <bors@rust-lang.org> | 2020-05-29 23:43:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-05-29 23:43:20 +0000 |
| commit | 0e9e4083100aa3ebf09b8f1ace0348cb37475eb9 (patch) | |
| tree | 1bb8b3fa49e034b12057f85edfa1e7ac0f5dda74 /src/liballoc | |
| parent | 4bd32c98047a809ba5fd1fac2aa044638e5f2105 (diff) | |
| parent | 37894559abd67dd9544f2d66b0e117573e38119c (diff) | |
| download | rust-0e9e4083100aa3ebf09b8f1ace0348cb37475eb9.tar.gz rust-0e9e4083100aa3ebf09b8f1ace0348cb37475eb9.zip | |
Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJung
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8ef6090c743..8cc6f04c065 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -865,6 +865,25 @@ impl From<Box<str>> for Box<[u8]> { } } +#[stable(feature = "box_from_array", since = "1.45.0")] +impl<T, const N: usize> From<[T; N]> for Box<[T]> +where + [T; N]: LengthAtMost32, +{ + /// Converts a `[T; N]` into a `Box<[T]>` + /// + /// This conversion moves the array to newly heap-allocated memory. + /// + /// # Examples + /// ```rust + /// let boxed: Box<[u8]> = Box::from([4, 2]); + /// println!("{:?}", boxed); + /// ``` + fn from(array: [T; N]) -> Box<[T]> { + box array + } +} + #[stable(feature = "boxed_slice_try_from", since = "1.43.0")] impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> where |
