Skip to content

Commit aed0d0f

Browse files
authored
Unrolled build for #145562
Rollup merge of #145562 - tbu-:pr_simplify_to_string_spec, r=tgross35 Simplify macro generating ToString implementations for `&…&str` Use deref coercion to let the compiler remove any amount of references. Also use that macro for `Cow` and `String`.
2 parents b2dd217 + cb5a4d1 commit aed0d0f

File tree

1 file changed

+23
-50
lines changed

1 file changed

+23
-50
lines changed

library/alloc/src/string.rs

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,68 +2939,41 @@ impl SpecToString for i8 {
29392939
}
29402940
}
29412941

2942-
// Generic/generated code can sometimes have multiple, nested references
2943-
// for strings, including `&&&str`s that would never be written
2944-
// by hand. This macro generates twelve layers of nested `&`-impl
2945-
// for primitive strings.
2946-
#[cfg(not(no_global_oom_handling))]
2947-
macro_rules! to_string_str_wrap_in_ref {
2948-
{x $($x:ident)*} => {
2949-
&to_string_str_wrap_in_ref! { $($x)* }
2950-
};
2951-
{} => { str };
2952-
}
2953-
#[cfg(not(no_global_oom_handling))]
2954-
macro_rules! to_string_expr_wrap_in_deref {
2955-
{$self:expr ; x $($x:ident)*} => {
2956-
*(to_string_expr_wrap_in_deref! { $self ; $($x)* })
2957-
};
2958-
{$self:expr ;} => { $self };
2959-
}
29602942
#[cfg(not(no_global_oom_handling))]
29612943
macro_rules! to_string_str {
2962-
{$($($x:ident)*),+} => {
2944+
{$($type:ty,)*} => {
29632945
$(
2964-
impl SpecToString for to_string_str_wrap_in_ref!($($x)*) {
2946+
impl SpecToString for $type {
29652947
#[inline]
29662948
fn spec_to_string(&self) -> String {
2967-
String::from(to_string_expr_wrap_in_deref!(self ; $($x)*))
2949+
let s: &str = self;
2950+
String::from(s)
29682951
}
29692952
}
2970-
)+
2953+
)*
29712954
};
29722955
}
29732956

29742957
#[cfg(not(no_global_oom_handling))]
29752958
to_string_str! {
2976-
x x x x x x x x x x x x,
2977-
x x x x x x x x x x x,
2978-
x x x x x x x x x x,
2979-
x x x x x x x x x,
2980-
x x x x x x x x,
2981-
x x x x x x x,
2982-
x x x x x x,
2983-
x x x x x,
2984-
x x x x,
2985-
x x x,
2986-
x x,
2987-
x,
2988-
}
2989-
2990-
#[cfg(not(no_global_oom_handling))]
2991-
impl SpecToString for Cow<'_, str> {
2992-
#[inline]
2993-
fn spec_to_string(&self) -> String {
2994-
self[..].to_owned()
2995-
}
2996-
}
2997-
2998-
#[cfg(not(no_global_oom_handling))]
2999-
impl SpecToString for String {
3000-
#[inline]
3001-
fn spec_to_string(&self) -> String {
3002-
self.to_owned()
3003-
}
2959+
Cow<'_, str>,
2960+
String,
2961+
// Generic/generated code can sometimes have multiple, nested references
2962+
// for strings, including `&&&str`s that would never be written
2963+
// by hand.
2964+
&&&&&&&&&&&&str,
2965+
&&&&&&&&&&&str,
2966+
&&&&&&&&&&str,
2967+
&&&&&&&&&str,
2968+
&&&&&&&&str,
2969+
&&&&&&&str,
2970+
&&&&&&str,
2971+
&&&&&str,
2972+
&&&&str,
2973+
&&&str,
2974+
&&str,
2975+
&str,
2976+
str,
30042977
}
30052978

30062979
#[cfg(not(no_global_oom_handling))]

0 commit comments

Comments
 (0)