Skip to content

Commit b2abb2b

Browse files
Rollup merge of #111966 - saethlin:inline-slice-tryfrom, r=thomcc
Add #[inline] to array TryFrom impls I was looking into #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`
2 parents ddb5424 + e1b8fad commit b2abb2b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/core/src/array/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ where
204204
{
205205
type Error = TryFromSliceError;
206206

207+
#[inline]
207208
fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> {
208209
<&Self>::try_from(slice).map(|r| *r)
209210
}
@@ -228,6 +229,7 @@ where
228229
{
229230
type Error = TryFromSliceError;
230231

232+
#[inline]
231233
fn try_from(slice: &mut [T]) -> Result<[T; N], TryFromSliceError> {
232234
<Self>::try_from(&*slice)
233235
}
@@ -249,6 +251,7 @@ where
249251
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
250252
type Error = TryFromSliceError;
251253

254+
#[inline]
252255
fn try_from(slice: &'a [T]) -> Result<&'a [T; N], TryFromSliceError> {
253256
if slice.len() == N {
254257
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] {
276279
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N] {
277280
type Error = TryFromSliceError;
278281

282+
#[inline]
279283
fn try_from(slice: &'a mut [T]) -> Result<&'a mut [T; N], TryFromSliceError> {
280284
if slice.len() == N {
281285
let ptr = slice.as_mut_ptr() as *mut [T; N];

0 commit comments

Comments
 (0)