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`
This commit is contained in:
Guillaume Gomez
2023-05-27 13:38:31 +02:00
committed by GitHub
+4
View File
@@ -204,6 +204,7 @@ fn borrow_mut(&mut self) -> &mut [T] {
{
type Error = TryFromSliceError;
#[inline]
fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> {
<&Self>::try_from(slice).map(|r| *r)
}
@@ -228,6 +229,7 @@ fn borrow_mut(&mut self) -> &mut [T] {
{
type Error = TryFromSliceError;
#[inline]
fn try_from(slice: &mut [T]) -> Result<[T; N], TryFromSliceError> {
<Self>::try_from(&*slice)
}
@@ -249,6 +251,7 @@ fn borrow_mut(&mut self) -> &mut [T] {
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 @@ fn borrow_mut(&mut self) -> &mut [T] {
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];