Skip to content

Commit 6b1f4e4

Browse files
authored
Rollup merge of #122977 - cuviper:as_statically_known_str, r=RalfJung
Rename `Arguments::as_const_str` to `as_statically_known_str` While `const` has a particular meaning about language guarantees, here we need a fuzzier notion like whether constant propagation was effective, and `statically_known` is the best term we have for now. r? ``@RalfJung``
2 parents 5281fe2 + b67ad8f commit 6b1f4e4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

library/core/src/fmt/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub trait Write {
201201
impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
202202
#[inline]
203203
default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
204-
if let Some(s) = args.as_const_str() {
204+
if let Some(s) = args.as_statically_known_str() {
205205
self.write_str(s)
206206
} else {
207207
write(&mut self, args)
@@ -212,7 +212,7 @@ pub trait Write {
212212
impl<W: Write> SpecWriteFmt for &mut W {
213213
#[inline]
214214
fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
215-
if let Some(s) = args.as_const_str() {
215+
if let Some(s) = args.as_statically_known_str() {
216216
self.write_str(s)
217217
} else {
218218
write(self, args)
@@ -442,7 +442,7 @@ impl<'a> Arguments<'a> {
442442
/// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
443443
#[must_use]
444444
#[inline]
445-
fn as_const_str(&self) -> Option<&'static str> {
445+
fn as_statically_known_str(&self) -> Option<&'static str> {
446446
let s = self.as_str();
447447
if core::intrinsics::is_val_statically_known(s.is_some()) { s } else { None }
448448
}
@@ -1617,7 +1617,11 @@ impl<'a> Formatter<'a> {
16171617
#[stable(feature = "rust1", since = "1.0.0")]
16181618
#[inline]
16191619
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
1620-
if let Some(s) = fmt.as_const_str() { self.buf.write_str(s) } else { write(self.buf, fmt) }
1620+
if let Some(s) = fmt.as_statically_known_str() {
1621+
self.buf.write_str(s)
1622+
} else {
1623+
write(self.buf, fmt)
1624+
}
16211625
}
16221626

16231627
/// Flags for formatting
@@ -2308,7 +2312,7 @@ impl Write for Formatter<'_> {
23082312

23092313
#[inline]
23102314
fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
2311-
if let Some(s) = args.as_const_str() {
2315+
if let Some(s) = args.as_statically_known_str() {
23122316
self.buf.write_str(s)
23132317
} else {
23142318
write(self.buf, args)

0 commit comments

Comments
 (0)