Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions library/core/src/ascii/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,26 @@ macro_rules! into_int_impl {

into_int_impl!(u8 u16 u32 u64 u128 char);

#[unstable(feature = "ascii_char", issue = "110998")]
impl AsRef<str> for AsciiChar {
#[inline(always)]
fn as_ref(&self) -> &str {
self.as_str()
}
}

#[unstable(feature = "ascii_char", issue = "110998")]
impl AsMut<str> for AsciiChar {
#[inline(always)]
fn as_mut(&mut self) -> &mut str {
let ascii_ptr: *mut [Self] = crate::slice::from_mut(self);
let str_ptr = ascii_ptr as *mut str;
// SAFETY: Each ASCII codepoint in UTF-8 is encoded as one single-byte
// code unit having the same value as the ASCII byte.
unsafe { &mut *str_ptr }
}
}

impl [AsciiChar] {
/// Views this slice of ASCII characters as a UTF-8 `str`.
#[unstable(feature = "ascii_char", issue = "110998")]
Expand Down
24 changes: 24 additions & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,30 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsRef<[Cell<T>; N]> for Cell<[T; N]> {
#[inline(always)]
fn as_ref(&self) -> &[Cell<T>; N] {
self.as_array_of_cells()
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsRef<[Cell<T>]> for Cell<[T; N]> {
#[inline(always)]
fn as_ref(&self) -> &[Cell<T>] {
&*self.as_array_of_cells()
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> AsRef<[Cell<T>]> for Cell<[T]> {
#[inline(always)]
fn as_ref(&self) -> &[Cell<T>] {
self.as_slice_of_cells()
}
}

impl<T> Cell<[T]> {
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
///
Expand Down
50 changes: 50 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,56 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> From<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]> {
#[inline(always)]
fn from(arr: [MaybeUninit<T>; N]) -> Self {
arr.transpose()
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsRef<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]> {
#[inline(always)]
fn as_ref(&self) -> &[MaybeUninit<T>; N] {
// SAFETY: T and MaybeUninit<T> have the same layout
unsafe { &*(self as *const MaybeUninit<[T; N]> as *const [MaybeUninit<T>; N]) }
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsRef<[MaybeUninit<T>]> for MaybeUninit<[T; N]> {
#[inline(always)]
fn as_ref(&self) -> &[MaybeUninit<T>] {
&*AsRef::<[MaybeUninit<T>; N]>::as_ref(self)
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsMut<[MaybeUninit<T>; N]> for MaybeUninit<[T; N]> {
#[inline(always)]
fn as_mut(&mut self) -> &mut [MaybeUninit<T>; N] {
// SAFETY: T and MaybeUninit<T> have the same layout
unsafe { &mut *(self as *mut MaybeUninit<[T; N]> as *mut [MaybeUninit<T>; N]) }
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> AsMut<[MaybeUninit<T>]> for MaybeUninit<[T; N]> {
#[inline(always)]
fn as_mut(&mut self) -> &mut [MaybeUninit<T>] {
&mut *AsMut::<[MaybeUninit<T>; N]>::as_mut(self)
}
}

#[stable(feature = "more_conversion_trait_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> From<MaybeUninit<[T; N]>> for [MaybeUninit<T>; N] {
#[inline(always)]
fn from(arr: MaybeUninit<[T; N]>) -> Self {
arr.transpose()
}
}

impl<T, const N: usize> [MaybeUninit<T>; N] {
/// Transposes a `[MaybeUninit<T>; N]` into a `MaybeUninit<[T; N]>`.
///
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/issue-71394-no-from-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ LL | let _: &[i8] = data.into();
| ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]`
|
= help: the following other types implement trait `From<T>`:
`[MaybeUninit<T>; N]` implements `From<MaybeUninit<[T; N]>>`
`[T; 10]` implements `From<(T, T, T, T, T, T, T, T, T, T)>`
`[T; 11]` implements `From<(T, T, T, T, T, T, T, T, T, T, T)>`
`[T; 12]` implements `From<(T, T, T, T, T, T, T, T, T, T, T, T)>`
`[T; 1]` implements `From<(T,)>`
`[T; 2]` implements `From<(T, T)>`
`[T; 3]` implements `From<(T, T, T)>`
`[T; 4]` implements `From<(T, T, T, T)>`
`[T; 5]` implements `From<(T, T, T, T, T)>`
and 6 others
and 7 others
= note: required for `&[u8]` to implement `Into<&[i8]>`

error: aborting due to 1 previous error
Expand Down
Loading