diff options
| author | bors <bors@rust-lang.org> | 2025-08-27 12:35:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-27 12:35:21 +0000 |
| commit | 3c91be712d3d84f6345cd22eae34c47b3a22a3d3 (patch) | |
| tree | b92bd52c33056589610a91d1fc6cf3fcb9948eb3 /library/alloc/src | |
| parent | b2dd217dd0a099fb87601657ec480bf3e92b30a6 (diff) | |
| parent | bd90013b397049e0ae939965add662d0a19761fb (diff) | |
| download | rust-3c91be712d3d84f6345cd22eae34c47b3a22a3d3.tar.gz rust-3c91be712d3d84f6345cd22eae34c47b3a22a3d3.zip | |
Auto merge of #145923 - matthiaskrgr:rollup-rkejtos, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang/rust#144274 (add Option::reduce) - rust-lang/rust#145562 (Simplify macro generating ToString implementations for `&…&str`) - rust-lang/rust#145625 (improve float to_degrees/to_radians rounding comments and impl) - rust-lang/rust#145740 (Introduce a `[workspace.dependencies`] section in the top-level `Cargo.toml`) - rust-lang/rust#145885 (Inherit TCC in debuginfo tests on macOS) - rust-lang/rust#145905 (Stop calling unwrap when format foreign has trailing dollar) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/string.rs | 73 |
1 files changed, 23 insertions, 50 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 11fd4346ff5..1d0dd4be1b6 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2939,68 +2939,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))] |
