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
12 changes: 6 additions & 6 deletions library/alloc/src/boxed/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ unsafe fn boxed_slice_as_array_unchecked<T, A: Allocator, const N: usize>(
}

#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
type Error = Box<[T]>;
impl<T, const N: usize, A: Allocator> TryFrom<Box<[T], A>> for Box<[T; N], A> {
type Error = Box<[T], A>;

/// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`.
///
Expand All @@ -269,7 +269,7 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
///
/// Returns the old `Box<[T]>` in the `Err` variant if
/// `boxed_slice.len()` does not equal `N`.
fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> {
fn try_from(boxed_slice: Box<[T], A>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
// SAFETY: Checked length.
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
Expand All @@ -281,8 +281,8 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
type Error = Vec<T>;
impl<T, const N: usize, A: Allocator> TryFrom<Vec<T, A>> for Box<[T; N], A> {
type Error = Vec<T, A>;

/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
///
Expand All @@ -302,7 +302,7 @@ impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
/// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
/// assert_eq!(state.len(), 100);
/// ```
fn try_from(vec: Vec<T>) -> Result<Self, Self::Error> {
fn try_from(vec: Vec<T, A>) -> Result<Self, Self::Error> {
if vec.len() == N {
let boxed_slice = vec.into_boxed_slice();
// SAFETY: Checked length.
Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use core::ops::{
use core::str::{FromStr, Utf8Error};
use core::{fmt, hash};

use crate::alloc::Allocator;
use crate::borrow::{Cow, ToOwned};
use crate::boxed::Box;
#[cfg(not(no_rc))]
Expand Down Expand Up @@ -597,10 +598,10 @@ impl<'a> TryFrom<&'a ByteString> for &'a str {
// Additional impls for `ByteStr` that require types from `alloc`:

#[unstable(feature = "bstr", issue = "134915")]
impl Clone for Box<ByteStr> {
impl<A: Allocator + Clone> Clone for Box<ByteStr, A> {
#[inline]
fn clone(&self) -> Self {
Self::from(Box::<[u8]>::from(&self.0))
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use core::slice::memchr;
use core::str::{self, FromStr, Utf8Error};
use core::{fmt, mem, ops, ptr, slice};

use crate::alloc::Allocator;
use crate::borrow::{Cow, ToOwned};
use crate::boxed::Box;
use crate::rc::Rc;
Expand Down Expand Up @@ -863,10 +864,10 @@ impl TryFrom<CString> for String {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<CStr> {
impl<A: Allocator + Clone> Clone for Box<CStr, A> {
#[inline]
fn clone(&self) -> Self {
(**self).into()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod tests;

use core::clone::CloneToUninit;

use crate::alloc::Allocator;
use crate::borrow::{Borrow, Cow};
use crate::collections::TryReserveError;
use crate::hash::{Hash, Hasher};
Expand Down Expand Up @@ -1395,10 +1396,10 @@ impl From<OsString> for Box<OsStr> {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<OsStr> {
impl<A: Allocator + Clone> Clone for Box<OsStr, A> {
#[inline]
fn clone(&self) -> Self {
self.to_os_string().into_boxed_os_str()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

use core::clone::CloneToUninit;

use crate::alloc::Allocator;
use crate::borrow::{Borrow, Cow};
use crate::collections::TryReserveError;
use crate::error::Error;
Expand Down Expand Up @@ -1972,10 +1973,10 @@ impl From<PathBuf> for Box<Path> {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<Path> {
impl<A: Allocator + Clone> Clone for Box<Path, A> {
#[inline]
fn clone(&self) -> Self {
self.to_path_buf().into_boxed_path()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
Loading