From 203bbfa2f76090e51e237da1017de19497b36d0e Mon Sep 17 00:00:00 2001 From: Ezra Shaw Date: Mon, 9 Jan 2023 22:21:21 +1300 Subject: [PATCH] impl: specialize impl of `ToString` on `bool` --- library/alloc/src/string.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 24f1b3a1c87..3118c7189a5 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2548,6 +2548,15 @@ fn to_string(&self) -> String { } } +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "bool_to_string_specialization", since = "CURRENT_RUSTC_VERSION")] +impl ToString for bool { + #[inline] + fn to_string(&self) -> String { + String::from(if *self { "true" } else { "false" }) + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "u8_to_string_specialization", since = "1.54.0")] impl ToString for u8 {