Skip to content

Commit

Permalink
Rollup merge of rust-lang#111966 - saethlin:inline-slice-tryfrom, r=t…
Browse files Browse the repository at this point in the history
…homcc

Add #[inline] to array TryFrom impls

I was looking into rust-lang#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`
  • Loading branch information
GuillaumeGomez authored May 27, 2023
2 parents ddb5424 + e1b8fad commit b2abb2b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -228,6 +229,7 @@ where
{
type Error = TryFromSliceError;

#[inline]
fn try_from(slice: &mut [T]) -> Result<[T; N], TryFromSliceError> {
<Self>::try_from(&*slice)
}
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b2abb2b

Please sign in to comment.