From fe6c6bde23be8ae5372e3cf922ca5877d22b2bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 25 Jul 2023 21:46:18 +0200 Subject: [PATCH] core, std, proc_macro:inline format!() args --- library/core/src/net/ip_addr.rs | 8 ++++---- library/core/src/num/mod.rs | 3 +-- library/core/src/panic/panic_info.rs | 4 ++-- library/core/src/str/lossy.rs | 2 +- library/core/src/str/mod.rs | 9 +-------- library/core/src/time.rs | 6 +++--- library/proc_macro/src/bridge/symbol.rs | 4 ++-- library/proc_macro/src/lib.rs | 6 +++--- library/std/src/backtrace.rs | 6 +++--- library/std/src/env.rs | 2 +- library/std/src/io/error/repr_bitpacked.rs | 5 ++--- library/std/src/sys/unix/process/process_common.rs | 2 +- library/std/src/sys/unix/process/process_unix.rs | 3 +-- library/test/src/formatters/junit.rs | 2 +- 14 files changed, 26 insertions(+), 36 deletions(-) diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 56460c75eba9d..b902540b9f346 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -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 { @@ -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(()) @@ -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()) } diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 95dcaf5dd7397..6cb9dd38c1d98 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1434,8 +1434,7 @@ fn from_str_radix(src: &str, radix: u32) -> Result { 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::() here // since String is not available in core! diff --git a/library/core/src/str/lossy.rs b/library/core/src/str/lossy.rs index 59f873d1268ce..b9b24b3865046 100644 --- a/library/core/src/str/lossy.rs +++ b/library/core/src/str/lossy.rs @@ -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}")?; } } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 9a93bb72903f2..4119abbd1849a 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -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 }; diff --git a/library/core/src/time.rs b/library/core/src/time.rs index b08d5782ab6f4..00428ee540bbe 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -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). @@ -1132,7 +1132,7 @@ impl fmt::Debug for Duration { write!(f, ".{:0 Literal { - let quoted = format!("{:?}", string); + let quoted = format!("{string:?}"); assert!(quoted.starts_with('"') && quoted.ends_with('"')); let symbol = "ed[1..quoted.len() - 1]; Literal::new(bridge::LitKind::Str, symbol, None) @@ -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 = "ed[1..quoted.len() - 1]; Literal::new(bridge::LitKind::Char, symbol, None) diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 7543ffadd4140..7668ff418ad2c 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -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: ")?; } 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, " }}") diff --git a/library/std/src/env.rs b/library/std/src/env.rs index d372fa64065f5..32a079cb809f8 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -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:?}") } } } diff --git a/library/std/src/io/error/repr_bitpacked.rs b/library/std/src/io/error/repr_bitpacked.rs index f94f88bac417e..361b4183c5648 100644 --- a/library/std/src/io/error/repr_bitpacked.rs +++ b/library/std/src/io/error/repr_bitpacked.rs @@ -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 } @@ -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`. // diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 640648e870748..e4d1f4f5664e8 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -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(()) } diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 0ce93af66ac0f..6bb443b54343e 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -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"); diff --git a/library/test/src/formatters/junit.rs b/library/test/src/formatters/junit.rs index a211ebf1ded16..755275580e2b0 100644 --- a/library/test/src/formatters/junit.rs +++ b/library/test/src/formatters/junit.rs @@ -35,7 +35,7 @@ fn str_to_cdata(s: &str) -> String { let escaped_output = escaped_output.replace('\n', "]]> ", ""); - format!("", escaped_output) + format!("") } impl OutputFormatter for JunitFormatter {