Skip to content
Merged
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
73 changes: 23 additions & 50 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2949,68 +2949,41 @@ impl SpecToString for i8 {
}
}

// Generic/generated code can sometimes have multiple, nested references
// for strings, including `&&&str`s that would never be written
// by hand. This macro generates twelve layers of nested `&`-impl
// for primitive strings.
#[cfg(not(no_global_oom_handling))]
macro_rules! to_string_str_wrap_in_ref {
{x $($x:ident)*} => {
&to_string_str_wrap_in_ref! { $($x)* }
};
{} => { str };
}
#[cfg(not(no_global_oom_handling))]
macro_rules! to_string_expr_wrap_in_deref {
{$self:expr ; x $($x:ident)*} => {
*(to_string_expr_wrap_in_deref! { $self ; $($x)* })
};
{$self:expr ;} => { $self };
}
#[cfg(not(no_global_oom_handling))]
macro_rules! to_string_str {
{$($($x:ident)*),+} => {
{$($type:ty,)*} => {
$(
impl SpecToString for to_string_str_wrap_in_ref!($($x)*) {
impl SpecToString for $type {
#[inline]
fn spec_to_string(&self) -> String {
String::from(to_string_expr_wrap_in_deref!(self ; $($x)*))
let s: &str = self;
String::from(s)
}
}
)+
)*
};
}

#[cfg(not(no_global_oom_handling))]
to_string_str! {
x x x x x x x x x x x x,
x x x x x x x x x x x,
x x x x x x x x x x,
x x x x x x x x x,
x x x x x x x x,
x x x x x x x,
x x x x x x,
x x x x x,
x x x x,
x x x,
x x,
x,
}

#[cfg(not(no_global_oom_handling))]
impl SpecToString for Cow<'_, str> {
#[inline]
fn spec_to_string(&self) -> String {
self[..].to_owned()
}
}

#[cfg(not(no_global_oom_handling))]
impl SpecToString for String {
#[inline]
fn spec_to_string(&self) -> String {
self.to_owned()
}
Cow<'_, str>,
String,
// Generic/generated code can sometimes have multiple, nested references
// for strings, including `&&&str`s that would never be written
// by hand.
&&&&&&&&&&&&str,
&&&&&&&&&&&str,
&&&&&&&&&&str,
&&&&&&&&&str,
&&&&&&&&str,
&&&&&&&str,
&&&&&&str,
&&&&&str,
&&&&str,
&&&str,
&&str,
&str,
str,
}

#[cfg(not(no_global_oom_handling))]
Expand Down
Loading