Skip to content

Commit ffa62b2

Browse files
committed
alloc: make to_string_str! a bit less complex
1 parent 20c833c commit ffa62b2

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

library/alloc/src/string.rs

+32-22
Original file line numberDiff line numberDiff line change
@@ -2647,37 +2647,47 @@ impl ToString for i8 {
26472647
// for strings, including `&&&str`s that would never be written
26482648
// by hand. This macro generates twelve layers of nested `&`-impl
26492649
// for primitive strings.
2650-
macro_rules! to_string_str {
2651-
{type ; x $($x:ident)*} => {
2652-
&to_string_str! { type ; $($x)* }
2653-
};
2654-
{type ;} => { str };
2655-
{impl ; x $($x:ident)*} => {
2656-
to_string_str! { $($x)* }
2650+
macro_rules! to_string_str_wrap_in_ref {
2651+
{x $($x:ident)*} => {
2652+
&to_string_str_wrap_in_ref! { $($x)* }
26572653
};
2658-
{impl ;} => { };
2654+
{} => { str };
2655+
}
2656+
macro_rules! to_string_expr_wrap_in_deref {
26592657
{$self:expr ; x $($x:ident)*} => {
2660-
*(to_string_str! { $self ; $($x)* })
2658+
*(to_string_expr_wrap_in_deref! { $self ; $($x)* })
26612659
};
26622660
{$self:expr ;} => { $self };
2663-
{$($x:ident)*} => {
2664-
#[doc(hidden)]
2665-
#[cfg(not(no_global_oom_handling))]
2666-
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
2667-
impl ToString for to_string_str!(type ; $($x)*) {
2668-
#[inline]
2669-
fn to_string(&self) -> String {
2670-
String::from(to_string_str!(self ; $($x)*))
2661+
}
2662+
macro_rules! to_string_str {
2663+
{$($($x:ident)*),+} => {
2664+
$(
2665+
#[doc(hidden)]
2666+
#[cfg(not(no_global_oom_handling))]
2667+
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
2668+
impl ToString for to_string_str_wrap_in_ref!($($x)*) {
2669+
#[inline]
2670+
fn to_string(&self) -> String {
2671+
String::from(to_string_expr_wrap_in_deref!(self ; $($x)*))
2672+
}
26712673
}
2672-
}
2673-
to_string_str! { impl ; $($x)* }
2674+
)+
26742675
};
26752676
}
26762677

26772678
to_string_str! {
2678-
x x x x
2679-
x x x x
2680-
x x x x
2679+
x x x x x x x x x x x x,
2680+
x x x x x x x x x x x,
2681+
x x x x x x x x x x,
2682+
x x x x x x x x x,
2683+
x x x x x x x x,
2684+
x x x x x x x,
2685+
x x x x x x,
2686+
x x x x x,
2687+
x x x x,
2688+
x x x,
2689+
x x,
2690+
x,
26812691
}
26822692

26832693
#[doc(hidden)]

0 commit comments

Comments
 (0)