diff options
| author | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2024-02-14 18:48:02 -0500 |
|---|---|---|
| committer | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2024-02-20 01:11:16 -0500 |
| commit | c50779fc78752c109d41108da0ef2b284d5a9462 (patch) | |
| tree | a4903f86378ece1ef8d1d2364dd0d83693fda70a | |
| parent | 6fa7d6ca16f5f3704bfd48fd3721e8ea329e971b (diff) | |
| download | rust-c50779fc78752c109d41108da0ef2b284d5a9462.tar.gz rust-c50779fc78752c109d41108da0ef2b284d5a9462.zip | |
Fix inlining issue for non-const case
| -rw-r--r-- | library/core/src/fmt/mod.rs | 31 | ||||
| -rw-r--r-- | library/core/src/lib.rs | 1 |
2 files changed, 20 insertions, 12 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index dde8c0c5e2b..3c9cd093ad8 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -201,14 +201,22 @@ pub trait Write { impl<W: Write + ?Sized> SpecWriteFmt for &mut W { #[inline] default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_str() { self.write_str(s) } else { write(&mut self, args) } + if let Some(s) = args.as_const_str() { + self.write_str(s) + } else { + write(&mut self, args) + } } } impl<W: Write> SpecWriteFmt for &mut W { #[inline] fn spec_write_fmt(self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_str() { self.write_str(s) } else { write(self, args) } + if let Some(s) = args.as_const_str() { + self.write_str(s) + } else { + write(self, args) + } } } @@ -431,17 +439,12 @@ impl<'a> Arguments<'a> { } } - /// Same as `as_str`, but will only return a `Some` value if it can be determined at compile time. + /// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time. + #[must_use] #[inline] const fn as_const_str(&self) -> Option<&'static str> { let s = self.as_str(); - // if unsafe { core::intrinsics::is_val_statically_known(matches!((self.pieces, self.args), ([], []) | ([_], []))) } { - if unsafe { core::intrinsics::is_val_statically_known(s) } { - s - } else { - None - } - + if unsafe { core::intrinsics::is_val_statically_known(s.is_some()) } { s } else { None } } } @@ -1597,7 +1600,7 @@ impl<'a> Formatter<'a> { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result { - if let Some(s) = fmt.as_str() { self.buf.write_str(s) } else { write(self.buf, fmt) } + if let Some(s) = fmt.as_const_str() { self.buf.write_str(s) } else { write(self.buf, fmt) } } /// Flags for formatting @@ -2288,7 +2291,11 @@ impl Write for Formatter<'_> { #[inline] fn write_fmt(&mut self, args: Arguments<'_>) -> Result { - if let Some(s) = args.as_str() { self.buf.write_str(s) } else { write(self.buf, args) } + if let Some(s) = args.as_const_str() { + self.buf.write_str(s) + } else { + write(self.buf, args) + } } } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b54680a61b4..ffaf8af0b11 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -176,6 +176,7 @@ #![feature(ip)] #![feature(ip_bits)] #![feature(is_ascii_octdigit)] +#![feature(is_val_statically_known)] #![feature(isqrt)] #![feature(maybe_uninit_uninit_array)] #![feature(non_null_convenience)] |
