Skip to content

Commit c6bcdb7

Browse files
committed
constify From impls for the Cow::Borrowed variant
1 parent 637b50b commit c6bcdb7

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

library/alloc/src/bstr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ impl Clone for Box<ByteStr> {
598598
}
599599

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

library/alloc/src/ffi/c_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ impl<'a> From<CString> for Cow<'a, CStr> {
878878
}
879879

880880
#[stable(feature = "cow_from_cstr", since = "1.28.0")]
881-
impl<'a> From<&'a CStr> for Cow<'a, CStr> {
881+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
882+
impl<'a> const From<&'a CStr> for Cow<'a, CStr> {
882883
/// Converts a [`CStr`] into a borrowed [`Cow`] without copying or allocating.
883884
#[inline]
884885
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
@@ -110,6 +110,7 @@
110110
#![feature(const_convert)]
111111
#![feature(const_default)]
112112
#![feature(const_eval_select)]
113+
#![feature(const_from)]
113114
#![feature(const_heap)]
114115
#![feature(core_intrinsics)]
115116
#![feature(deprecated_suggestion)]

library/alloc/src/string.rs

Lines changed: 2 additions & 1 deletion
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.

library/alloc/src/vec/cow.rs

Lines changed: 4 additions & 2 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
///

0 commit comments

Comments
 (0)