diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 4016167d05c..e880d5758ec 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -201,7 +201,7 @@ trait SpecWriteFmt { impl SpecWriteFmt for &mut W { #[inline] default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_const_str() { + if let Some(s) = args.as_statically_known_str() { self.write_str(s) } else { write(&mut self, args) @@ -212,7 +212,7 @@ impl SpecWriteFmt for &mut W { impl SpecWriteFmt for &mut W { #[inline] fn spec_write_fmt(self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_const_str() { + if let Some(s) = args.as_statically_known_str() { self.write_str(s) } else { write(self, args) @@ -442,7 +442,7 @@ pub const fn as_str(&self) -> Option<&'static str> { /// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time. #[must_use] #[inline] - fn as_const_str(&self) -> Option<&'static str> { + fn as_statically_known_str(&self) -> Option<&'static str> { let s = self.as_str(); if core::intrinsics::is_val_statically_known(s.is_some()) { s } else { None } } @@ -1617,7 +1617,11 @@ pub fn write_str(&mut self, data: &str) -> Result { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result { - if let Some(s) = fmt.as_const_str() { self.buf.write_str(s) } else { write(self.buf, fmt) } + if let Some(s) = fmt.as_statically_known_str() { + self.buf.write_str(s) + } else { + write(self.buf, fmt) + } } /// Flags for formatting @@ -2308,7 +2312,7 @@ fn write_char(&mut self, c: char) -> Result { #[inline] fn write_fmt(&mut self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_const_str() { + if let Some(s) = args.as_statically_known_str() { self.buf.write_str(s) } else { write(self.buf, args)