From ebd14675ee612527e07762ac0645075c9524e5b1 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Mon, 25 Jul 2022 13:05:51 -0700 Subject: [PATCH] Extend const_convert for Cow on From<&str> and From These implementations are trivially const - since they only create the enum structure without running any non-const code. const_convert is tracked by #88674 --- library/alloc/src/string.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index b1513e5e0f31c..b3f0bc6baac49 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2701,7 +2701,8 @@ impl<'a> From> 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_convert", issue = "88674")] +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. @@ -2722,7 +2723,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 for Cow<'a, str> { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<'a> const From for Cow<'a, str> { /// Converts a [`String`] into an [`Owned`] variant. /// No heap allocation is performed, and the string /// is not copied.