Skip to content

Commit da0d7c7

Browse files
authored
Rollup merge of rust-lang#146067 - npmccallum:cow, r=oli-obk
alloc: make Cow From impls const This is an expansion of rust-lang#143773 for the `Cow` `From` conversions. r? `@oli-obk`
2 parents aa3a657 + 2784327 commit da0d7c7

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

library/alloc/src/bstr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ impl<'a> From<&'a ByteStr> for ByteString {
245245
}
246246

247247
#[unstable(feature = "bstr", issue = "134915")]
248-
impl<'a> From<ByteString> for Cow<'a, ByteStr> {
248+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
249+
impl<'a> const From<ByteString> for Cow<'a, ByteStr> {
249250
#[inline]
250251
fn from(s: ByteString) -> Self {
251252
Cow::Owned(s)
@@ -598,7 +599,8 @@ impl Clone for Box<ByteStr> {
598599
}
599600

600601
#[unstable(feature = "bstr", issue = "134915")]
601-
impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
602+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
603+
impl<'a> const From<&'a ByteStr> for Cow<'a, ByteStr> {
602604
#[inline]
603605
fn from(s: &'a ByteStr) -> Self {
604606
Cow::Borrowed(s)

library/alloc/src/ffi/c_str.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ impl From<CString> for Box<CStr> {
869869
}
870870

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

880881
#[stable(feature = "cow_from_cstr", since = "1.28.0")]
881-
impl<'a> From<&'a CStr> for Cow<'a, CStr> {
882+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
883+
impl<'a> const From<&'a CStr> for Cow<'a, CStr> {
882884
/// Converts a [`CStr`] into a borrowed [`Cow`] without copying or allocating.
883885
#[inline]
884886
fn from(s: &'a CStr) -> Cow<'a, CStr> {

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#![feature(coerce_unsized)]
110110
#![feature(const_default)]
111111
#![feature(const_eval_select)]
112+
#![feature(const_from)]
112113
#![feature(const_heap)]
113114
#![feature(const_trait_impl)]
114115
#![feature(core_intrinsics)]

library/alloc/src/string.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,8 @@ impl<'a> From<Cow<'a, str>> for String {
31093109

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

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

31543156
#[cfg(not(no_global_oom_handling))]
31553157
#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
3156-
impl<'a> From<&'a String> for Cow<'a, str> {
3158+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
3159+
impl<'a> const From<&'a String> for Cow<'a, str> {
31573160
/// Converts a [`String`] reference into a [`Borrowed`] variant.
31583161
/// No heap allocation is performed, and the string
31593162
/// is not copied.

library/alloc/src/vec/cow.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use super::Vec;
22
use crate::borrow::Cow;
33

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

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

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

4346
#[stable(feature = "cow_from_vec_ref", since = "1.28.0")]
44-
impl<'a, T: Clone> From<&'a Vec<T>> for Cow<'a, [T]> {
47+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
48+
impl<'a, T: Clone> const From<&'a Vec<T>> for Cow<'a, [T]> {
4549
/// Creates a [`Borrowed`] variant of [`Cow`]
4650
/// from a reference to [`Vec`].
4751
///

0 commit comments

Comments
 (0)