Skip to content

Commit fe6c6bd

Browse files
committed
core, std, proc_macro:inline format!() args
1 parent 601a34d commit fe6c6bd

File tree

14 files changed

+26
-36
lines changed

14 files changed

+26
-36
lines changed

library/core/src/net/ip_addr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ impl fmt::Display for Ipv6Addr {
18631863
} else if self.is_loopback() {
18641864
f.write_str("::1")
18651865
} else if let Some(ipv4) = self.to_ipv4_mapped() {
1866-
write!(f, "::ffff:{}", ipv4)
1866+
write!(f, "::ffff:{ipv4}")
18671867
} else {
18681868
#[derive(Copy, Clone, Default)]
18691869
struct Span {
@@ -1899,10 +1899,10 @@ impl fmt::Display for Ipv6Addr {
18991899
#[inline]
19001900
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
19011901
if let Some((first, tail)) = chunk.split_first() {
1902-
write!(f, "{:x}", first)?;
1902+
write!(f, "{first:x}")?;
19031903
for segment in tail {
19041904
f.write_char(':')?;
1905-
write!(f, "{:x}", segment)?;
1905+
write!(f, "{segment:x}")?;
19061906
}
19071907
}
19081908
Ok(())
@@ -1921,7 +1921,7 @@ impl fmt::Display for Ipv6Addr {
19211921

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

19261926
f.pad(buf.as_str())
19271927
}

library/core/src/num/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
14341434

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

14411440
if src.is_empty() {

library/core/src/panic/panic_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ impl fmt::Display for PanicInfo<'_> {
148148
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
149149
formatter.write_str("panicked at ")?;
150150
if let Some(message) = self.message {
151-
write!(formatter, "'{}', ", message)?
151+
write!(formatter, "'{message}', ")?
152152
} else if let Some(payload) = self.payload.downcast_ref::<&'static str>() {
153-
write!(formatter, "'{}', ", payload)?
153+
write!(formatter, "'{payload}', ")?
154154
}
155155
// NOTE: we cannot use downcast_ref::<String>() here
156156
// since String is not available in core!

library/core/src/str/lossy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl fmt::Debug for Debug<'_> {
100100

101101
// Broken parts of string as hex escape.
102102
for &b in chunk.invalid() {
103-
write!(f, "\\x{:02X}", b)?;
103+
write!(f, "\\x{b:02X}")?;
104104
}
105105
}
106106

library/core/src/str/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
111111
}
112112

113113
// 2. begin <= end
114-
assert!(
115-
begin <= end,
116-
"begin <= end ({} <= {}) when slicing `{}`{}",
117-
begin,
118-
end,
119-
s_trunc,
120-
ellipsis
121-
);
114+
assert!((begin <= end), "begin ({begin}) <= end ({end}) when slicing `{s_trunc}`{ellipsis}");
122115

123116
// 3. character boundary
124117
let index = if !s.is_char_boundary(begin) { begin } else { end };

library/core/src/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,10 @@ impl fmt::Debug for Duration {
11151115
// padding (padding is calculated below).
11161116
let emit_without_padding = |f: &mut fmt::Formatter<'_>| {
11171117
if let Some(integer_part) = integer_part {
1118-
write!(f, "{}{}", prefix, integer_part)?;
1118+
write!(f, "{prefix}{integer_part}")?;
11191119
} else {
11201120
// u64::MAX + 1 == 18446744073709551616
1121-
write!(f, "{}18446744073709551616", prefix)?;
1121+
write!(f, "{prefix}18446744073709551616")?;
11221122
}
11231123

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

1135-
write!(f, "{}", postfix)
1135+
write!(f, "{postfix}")
11361136
};
11371137

11381138
match f.width() {

library/proc_macro/src/bridge/symbol.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Symbol {
3535
// Fast-path: check if this is a valid ASCII identifier
3636
if Self::is_valid_ascii_ident(string.as_bytes()) {
3737
if is_raw && !Self::can_be_raw(string) {
38-
panic!("`{}` cannot be a raw identifier", string);
38+
panic!("`{string}` cannot be a raw identifier");
3939
}
4040
return Self::new(string);
4141
}
@@ -49,7 +49,7 @@ impl Symbol {
4949
} else {
5050
client::Symbol::normalize_and_validate_ident(string)
5151
}
52-
.unwrap_or_else(|_| panic!("`{:?}` is not a valid identifier", string))
52+
.unwrap_or_else(|_| panic!("`{string:?}` is not a valid identifier"))
5353
}
5454

5555
/// Run a callback with the symbol's string value.

library/proc_macro/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ impl Punct {
947947
':', '#', '$', '?', '\'',
948948
];
949949
if !LEGAL_CHARS.contains(&ch) {
950-
panic!("unsupported character `{:?}`", ch);
950+
panic!("unsupported character `{ch:?}`");
951951
}
952952
Punct(bridge::Punct {
953953
ch: ch as u8,
@@ -1310,7 +1310,7 @@ impl Literal {
13101310
/// String literal.
13111311
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
13121312
pub fn string(string: &str) -> Literal {
1313-
let quoted = format!("{:?}", string);
1313+
let quoted = format!("{string:?}");
13141314
assert!(quoted.starts_with('"') && quoted.ends_with('"'));
13151315
let symbol = &quoted[1..quoted.len() - 1];
13161316
Literal::new(bridge::LitKind::Str, symbol, None)
@@ -1319,7 +1319,7 @@ impl Literal {
13191319
/// Character literal.
13201320
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
13211321
pub fn character(ch: char) -> Literal {
1322-
let quoted = format!("{:?}", ch);
1322+
let quoted = format!("{ch:?}");
13231323
assert!(quoted.starts_with('\'') && quoted.ends_with('\''));
13241324
let symbol = &quoted[1..quoted.len() - 1];
13251325
Literal::new(bridge::LitKind::Char, symbol, None)

library/std/src/backtrace.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,17 @@ impl fmt::Debug for BacktraceSymbol {
218218
write!(fmt, "{{ ")?;
219219

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

226226
if let Some(fname) = self.filename.as_ref() {
227-
write!(fmt, ", file: \"{:?}\"", fname)?;
227+
write!(fmt, ", file: \"{fname:?}\"")?;
228228
}
229229

230230
if let Some(line) = self.lineno {
231-
write!(fmt, ", line: {:?}", line)?;
231+
write!(fmt, ", line: {line:?}")?;
232232
}
233233

234234
write!(fmt, " }}")

library/std/src/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl fmt::Display for VarError {
291291
match *self {
292292
VarError::NotPresent => write!(f, "environment variable not found"),
293293
VarError::NotUnicode(ref s) => {
294-
write!(f, "environment variable was not valid unicode: {:?}", s)
294+
write!(f, "environment variable was not valid unicode: {s:?}")
295295
}
296296
}
297297
}

library/std/src/io/error/repr_bitpacked.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ impl Repr {
194194
// only run in std's tests, unless the user uses -Zbuild-std)
195195
debug_assert!(
196196
matches!(res.data(), ErrorData::Simple(k) if k == kind),
197-
"repr(simple) encoding failed {:?}",
198-
kind,
197+
"repr(simple) encoding failed {kind:?}",
199198
);
200199
res
201200
}
@@ -256,7 +255,7 @@ where
256255
TAG_SIMPLE => {
257256
let kind_bits = (bits >> 32) as u32;
258257
let kind = kind_from_prim(kind_bits).unwrap_or_else(|| {
259-
debug_assert!(false, "Invalid io::error::Repr bits: `Repr({:#018x})`", bits);
258+
debug_assert!(false, "Invalid io::error::Repr bits: `Repr({bits:#018x})`");
260259
// This means the `ptr` passed in was not valid, which violates
261260
// the unsafe contract of `decode_repr`.
262261
//

library/std/src/sys/unix/process/process_common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ impl fmt::Debug for Command {
569569
write!(f, "{:?}", self.args[0])?;
570570

571571
for arg in &self.args[1..] {
572-
write!(f, " {:?}", arg)?;
572+
write!(f, " {arg:?}")?;
573573
}
574574
Ok(())
575575
}

library/std/src/sys/unix/process/process_unix.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ impl Command {
146146
let (errno, footer) = bytes.split_at(4);
147147
assert_eq!(
148148
CLOEXEC_MSG_FOOTER, footer,
149-
"Validation on the CLOEXEC pipe failed: {:?}",
150-
bytes
149+
"Validation on the CLOEXEC pipe failed: {bytes:?}"
151150
);
152151
let errno = i32::from_be_bytes(errno.try_into().unwrap());
153152
assert!(p.wait().is_ok(), "wait() should either return Ok or panic");

library/test/src/formatters/junit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn str_to_cdata(s: &str) -> String {
3535
let escaped_output = escaped_output.replace('\n', "]]>&#xA;<![CDATA[");
3636
// Prune empty CDATA blocks resulting from any escaping
3737
let escaped_output = escaped_output.replace("<![CDATA[]]>", "");
38-
format!("<![CDATA[{}]]>", escaped_output)
38+
format!("<![CDATA[{escaped_output}]]>")
3939
}
4040

4141
impl<T: Write> OutputFormatter for JunitFormatter<T> {

0 commit comments

Comments
 (0)