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
6 changes: 4 additions & 2 deletions library/alloc/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ impl<'a> From<&'a ByteStr> for ByteString {
}

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> From<ByteString> for Cow<'a, ByteStr> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<ByteString> for Cow<'a, ByteStr> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have the equivalent for String? And is ByteString const constructible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk Yes, the equivalent for String is in this same patch.

ByteString is const constructible:

#[repr(transparent)]
pub struct ByteString(pub Vec<u8>);

Both Vec and String are const constructible:

https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new
https://doc.rust-lang.org/std/string/struct.String.html#method.new

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh lol i stopped scrolling and didnt see the other files

#[inline]
fn from(s: ByteString) -> Self {
Cow::Owned(s)
Expand Down Expand Up @@ -598,7 +599,8 @@ impl Clone for Box<ByteStr> {
}

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<&'a ByteStr> for Cow<'a, ByteStr> {
#[inline]
fn from(s: &'a ByteStr) -> Self {
Cow::Borrowed(s)
Expand Down
6 changes: 4 additions & 2 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ impl From<CString> for Box<CStr> {
}

#[stable(feature = "cow_from_cstr", since = "1.28.0")]
impl<'a> From<CString> for Cow<'a, CStr> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<CString> for Cow<'a, CStr> {
/// Converts a [`CString`] into an owned [`Cow`] without copying or allocating.
#[inline]
fn from(s: CString) -> Cow<'a, CStr> {
Expand All @@ -878,7 +879,8 @@ impl<'a> From<CString> for Cow<'a, CStr> {
}

#[stable(feature = "cow_from_cstr", since = "1.28.0")]
impl<'a> From<&'a CStr> for Cow<'a, CStr> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<&'a CStr> for Cow<'a, CStr> {
/// Converts a [`CStr`] into a borrowed [`Cow`] without copying or allocating.
#[inline]
fn from(s: &'a CStr) -> Cow<'a, CStr> {
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#![feature(coerce_unsized)]
#![feature(const_default)]
#![feature(const_eval_select)]
#![feature(const_from)]
#![feature(const_heap)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]
Expand Down
9 changes: 6 additions & 3 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3109,7 +3109,8 @@ impl<'a> From<Cow<'a, str>> for String {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a str> for Cow<'a, str> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<&'a str> for Cow<'a, str> {
/// Converts a string slice into a [`Borrowed`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
Expand All @@ -3130,7 +3131,8 @@ impl<'a> From<&'a str> for Cow<'a, str> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<String> for Cow<'a, str> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<String> for Cow<'a, str> {
/// Converts a [`String`] into an [`Owned`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
Expand All @@ -3153,7 +3155,8 @@ impl<'a> From<String> for Cow<'a, str> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
impl<'a> From<&'a String> for Cow<'a, str> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a> const From<&'a String> for Cow<'a, str> {
/// Converts a [`String`] reference into a [`Borrowed`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
Expand Down
12 changes: 8 additions & 4 deletions library/alloc/src/vec/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use super::Vec;
use crate::borrow::Cow;

#[stable(feature = "cow_from_vec", since = "1.8.0")]
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a, T: Clone> const From<&'a [T]> for Cow<'a, [T]> {
/// Creates a [`Borrowed`] variant of [`Cow`]
/// from a slice.
///
Expand All @@ -15,7 +16,8 @@ impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
}

#[stable(feature = "cow_from_array_ref", since = "1.77.0")]
impl<'a, T: Clone, const N: usize> From<&'a [T; N]> for Cow<'a, [T]> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a, T: Clone, const N: usize> const From<&'a [T; N]> for Cow<'a, [T]> {
/// Creates a [`Borrowed`] variant of [`Cow`]
/// from a reference to an array.
///
Expand All @@ -28,7 +30,8 @@ impl<'a, T: Clone, const N: usize> From<&'a [T; N]> for Cow<'a, [T]> {
}

#[stable(feature = "cow_from_vec", since = "1.8.0")]
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a, T: Clone> const From<Vec<T>> for Cow<'a, [T]> {
/// Creates an [`Owned`] variant of [`Cow`]
/// from an owned instance of [`Vec`].
///
Expand All @@ -41,7 +44,8 @@ impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
}

#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
impl<'a, T: Clone> const From<&'a Vec<T>> for Cow<'a, [T]> {
/// Creates a [`Borrowed`] variant of [`Cow`]
/// from a reference to [`Vec`].
///
Expand Down
Loading