Skip to content

core, std, proc_macro: inline format!() args (1) #114067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/core/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ impl fmt::Display for Ipv6Addr {
} else if self.is_loopback() {
f.write_str("::1")
} else if let Some(ipv4) = self.to_ipv4_mapped() {
write!(f, "::ffff:{}", ipv4)
write!(f, "::ffff:{ipv4}")
} else {
#[derive(Copy, Clone, Default)]
struct Span {
Expand Down Expand Up @@ -1899,10 +1899,10 @@ impl fmt::Display for Ipv6Addr {
#[inline]
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
if let Some((first, tail)) = chunk.split_first() {
write!(f, "{:x}", first)?;
write!(f, "{first:x}")?;
for segment in tail {
f.write_char(':')?;
write!(f, "{:x}", segment)?;
write!(f, "{segment:x}")?;
}
}
Ok(())
Expand All @@ -1921,7 +1921,7 @@ impl fmt::Display for Ipv6Addr {

let mut buf = DisplayBuffer::<{ LONGEST_IPV6_ADDR.len() }>::new();
// Buffer is long enough for the longest possible IPv6 address, so this should never fail.
write!(buf, "{}", self).unwrap();
write!(buf, "{self}").unwrap();

f.pad(buf.as_str())
}
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par

assert!(
(2..=36).contains(&radix),
"from_str_radix_int: must lie in the range `[2, 36]` - found {}",
radix
"from_str_radix_int: must lie in the range `[2, 36]` - found {radix}"
);

if src.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/panic/panic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ impl fmt::Display for PanicInfo<'_> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("panicked at ")?;
if let Some(message) = self.message {
write!(formatter, "'{}', ", message)?
write!(formatter, "'{message}', ")?
} else if let Some(payload) = self.payload.downcast_ref::<&'static str>() {
write!(formatter, "'{}', ", payload)?
write!(formatter, "'{payload}', ")?
}
// NOTE: we cannot use downcast_ref::<String>() here
// since String is not available in core!
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl fmt::Debug for Debug<'_> {

// Broken parts of string as hex escape.
for &b in chunk.invalid() {
write!(f, "\\x{:02X}", b)?;
write!(f, "\\x{b:02X}")?;
}
}

Expand Down
9 changes: 1 addition & 8 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
}

// 2. begin <= end
assert!(
begin <= end,
"begin <= end ({} <= {}) when slicing `{}`{}",
begin,
end,
s_trunc,
ellipsis
);
assert!((begin <= end), "begin ({begin}) <= end ({end}) when slicing `{s_trunc}`{ellipsis}");

// 3. character boundary
let index = if !s.is_char_boundary(begin) { begin } else { end };
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,10 @@ impl fmt::Debug for Duration {
// padding (padding is calculated below).
let emit_without_padding = |f: &mut fmt::Formatter<'_>| {
if let Some(integer_part) = integer_part {
write!(f, "{}{}", prefix, integer_part)?;
write!(f, "{prefix}{integer_part}")?;
} else {
// u64::MAX + 1 == 18446744073709551616
write!(f, "{}18446744073709551616", prefix)?;
write!(f, "{prefix}18446744073709551616")?;
}

// Write the decimal point and the fractional part (if any).
Expand All @@ -1132,7 +1132,7 @@ impl fmt::Debug for Duration {
write!(f, ".{:0<width$}", s, width = w)?;
}

write!(f, "{}", postfix)
write!(f, "{postfix}")
};

match f.width() {
Expand Down
4 changes: 2 additions & 2 deletions library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Symbol {
// Fast-path: check if this is a valid ASCII identifier
if Self::is_valid_ascii_ident(string.as_bytes()) {
if is_raw && !Self::can_be_raw(string) {
panic!("`{}` cannot be a raw identifier", string);
panic!("`{string}` cannot be a raw identifier");
}
return Self::new(string);
}
Expand All @@ -49,7 +49,7 @@ impl Symbol {
} else {
client::Symbol::normalize_and_validate_ident(string)
}
.unwrap_or_else(|_| panic!("`{:?}` is not a valid identifier", string))
.unwrap_or_else(|_| panic!("`{string:?}` is not a valid identifier"))
}

/// Run a callback with the symbol's string value.
Expand Down
6 changes: 3 additions & 3 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ impl Punct {
':', '#', '$', '?', '\'',
];
if !LEGAL_CHARS.contains(&ch) {
panic!("unsupported character `{:?}`", ch);
panic!("unsupported character `{ch:?}`");
}
Punct(bridge::Punct {
ch: ch as u8,
Expand Down Expand Up @@ -1310,7 +1310,7 @@ impl Literal {
/// String literal.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn string(string: &str) -> Literal {
let quoted = format!("{:?}", string);
let quoted = format!("{string:?}");
assert!(quoted.starts_with('"') && quoted.ends_with('"'));
let symbol = &quoted[1..quoted.len() - 1];
Literal::new(bridge::LitKind::Str, symbol, None)
Expand All @@ -1319,7 +1319,7 @@ impl Literal {
/// Character literal.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn character(ch: char) -> Literal {
let quoted = format!("{:?}", ch);
let quoted = format!("{ch:?}");
assert!(quoted.starts_with('\'') && quoted.ends_with('\''));
let symbol = &quoted[1..quoted.len() - 1];
Literal::new(bridge::LitKind::Char, symbol, None)
Expand Down
6 changes: 3 additions & 3 deletions library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ impl fmt::Debug for BacktraceSymbol {
write!(fmt, "{{ ")?;

if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) {
write!(fmt, "fn: \"{:#}\"", fn_name)?;
write!(fmt, "fn: \"{fn_name:#}\"")?;
} else {
write!(fmt, "fn: <unknown>")?;
}

if let Some(fname) = self.filename.as_ref() {
write!(fmt, ", file: \"{:?}\"", fname)?;
write!(fmt, ", file: \"{fname:?}\"")?;
}

if let Some(line) = self.lineno {
write!(fmt, ", line: {:?}", line)?;
write!(fmt, ", line: {line:?}")?;
}

write!(fmt, " }}")
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl fmt::Display for VarError {
match *self {
VarError::NotPresent => write!(f, "environment variable not found"),
VarError::NotUnicode(ref s) => {
write!(f, "environment variable was not valid unicode: {:?}", s)
write!(f, "environment variable was not valid unicode: {s:?}")
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions library/std/src/io/error/repr_bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ impl Repr {
// only run in std's tests, unless the user uses -Zbuild-std)
debug_assert!(
matches!(res.data(), ErrorData::Simple(k) if k == kind),
"repr(simple) encoding failed {:?}",
kind,
"repr(simple) encoding failed {kind:?}",
);
res
}
Expand Down Expand Up @@ -256,7 +255,7 @@ where
TAG_SIMPLE => {
let kind_bits = (bits >> 32) as u32;
let kind = kind_from_prim(kind_bits).unwrap_or_else(|| {
debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits);
debug_assert!(false, "Invalid io::error::Repr bits: `Repr({bits:#018x})`");
// This means the `ptr` passed in was not valid, which violates
// the unsafe contract of `decode_repr`.
//
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl fmt::Debug for Command {
write!(f, "{:?}", self.args[0])?;

for arg in &self.args[1..] {
write!(f, " {:?}", arg)?;
write!(f, " {arg:?}")?;
}
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ impl Command {
let (errno, footer) = bytes.split_at(4);
assert_eq!(
CLOEXEC_MSG_FOOTER, footer,
"Validation on the CLOEXEC pipe failed: {:?}",
bytes
"Validation on the CLOEXEC pipe failed: {bytes:?}"
);
let errno = i32::from_be_bytes(errno.try_into().unwrap());
assert!(p.wait().is_ok(), "wait() should either return Ok or panic");
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/formatters/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn str_to_cdata(s: &str) -> String {
let escaped_output = escaped_output.replace('\n', "]]>&#xA;<![CDATA[");
// Prune empty CDATA blocks resulting from any escaping
let escaped_output = escaped_output.replace("<![CDATA[]]>", "");
format!("<![CDATA[{}]]>", escaped_output)
format!("<![CDATA[{escaped_output}]]>")
}

impl<T: Write> OutputFormatter for JunitFormatter<T> {
Expand Down