diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-05-27 13:38:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-27 13:38:31 +0200 |
| commit | b2abb2b0567155042e72ad0b32b01b64aba40ab8 (patch) | |
| tree | aae64ba8a7d35ce74d4b6e914d019ec64897ed28 | |
| parent | ddb5424569b1d598adf9010cece8d49968c357e6 (diff) | |
| parent | e1b8fad66430abd03e611bb18425e085945c7c40 (diff) | |
| download | rust-b2abb2b0567155042e72ad0b32b01b64aba40ab8.tar.gz rust-b2abb2b0567155042e72ad0b32b01b64aba40ab8.zip | |
Rollup merge of #111966 - saethlin:inline-slice-tryfrom, r=thomcc
Add #[inline] to array TryFrom impls I was looking into https://github.com/rust-lang/rust/issues/111959 and I realized we don't have these. They seem like an uncontroversial addition. IMO this PR does not fix that issue. I think the bad codegen is being caused by some underlying deeper problem but this change might cause the MIR inliner to paper over it in this specific case. r? `@thomcc`
| -rw-r--r-- | library/core/src/array/mod.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index bdb4c975909..e3885d485b7 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -204,6 +204,7 @@ where { type Error = TryFromSliceError; + #[inline] fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> { <&Self>::try_from(slice).map(|r| *r) } @@ -228,6 +229,7 @@ where { type Error = TryFromSliceError; + #[inline] fn try_from(slice: &mut [T]) -> Result<[T; N], TryFromSliceError> { <Self>::try_from(&*slice) } @@ -249,6 +251,7 @@ where impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { type Error = TryFromSliceError; + #[inline] fn try_from(slice: &'a [T]) -> Result<&'a [T; N], TryFromSliceError> { if slice.len() == N { let ptr = slice.as_ptr() as *const [T; N]; @@ -276,6 +279,7 @@ impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] { impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] { type Error = TryFromSliceError; + #[inline] fn try_from(slice: &'a mut [T]) -> Result<&'a mut [T; N], TryFromSliceError> { if slice.len() == N { let ptr = slice.as_mut_ptr() as *mut [T; N]; |
