Skip to content

Commit 3f8575f

Browse files
committed
style: Inline fmt args
1 parent 889484d commit 3f8575f

File tree

10 files changed

+33
-36
lines changed

10 files changed

+33
-36
lines changed

crates/snapbox/src/assert/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl std::fmt::Display for Error {
3838
if let Some(backtrace) = self.backtrace.as_ref() {
3939
writeln!(f)?;
4040
writeln!(f, "Backtrace:")?;
41-
writeln!(f, "{}", backtrace)?;
41+
writeln!(f, "{backtrace}")?;
4242
}
4343
Ok(())
4444
}

crates/snapbox/src/assert/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Assert {
168168
crate::report::Styled::new(String::new(), Default::default())
169169
} else if let Some(action_var) = self.action_var.as_deref() {
170170
self.palette
171-
.hint(format!("Update with {}=overwrite", action_var))
171+
.hint(format!("Update with {action_var}=overwrite"))
172172
} else {
173173
crate::report::Styled::new(String::new(), Default::default())
174174
};
@@ -338,7 +338,7 @@ impl Assert {
338338
}
339339
if ok {
340340
use std::io::Write;
341-
let _ = write!(stderr(), "{}", buffer);
341+
let _ = write!(stderr(), "{buffer}");
342342
match self.action {
343343
Action::Skip => unreachable!("Bailed out earlier"),
344344
Action::Ignore => {
@@ -365,7 +365,7 @@ impl Assert {
365365
&mut buffer,
366366
"{}",
367367
self.palette
368-
.hint(format_args!("Update with {}=overwrite", action_var))
368+
.hint(format_args!("Update with {action_var}=overwrite"))
369369
)
370370
.unwrap();
371371
}

crates/snapbox/src/bin/snap-fixture.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use std::process;
88

99
fn run() -> Result<(), Box<dyn Error>> {
1010
if let Ok(text) = env::var("stdout") {
11-
println!("{}", text);
11+
println!("{text}");
1212
}
1313
if let Ok(text) = env::var("stderr") {
14-
eprintln!("{}", text);
14+
eprintln!("{text}");
1515
}
1616

1717
if env::var("echo_large").as_deref() == Ok("1") {
1818
for i in 0..(128 * 1024) {
19-
println!("{}", i);
19+
println!("{i}");
2020
}
2121
}
2222

@@ -33,7 +33,7 @@ fn run() -> Result<(), Box<dyn Error>> {
3333

3434
if let Ok(path) = env::var("cat") {
3535
let text = std::fs::read_to_string(path).unwrap();
36-
eprintln!("{}", text);
36+
eprintln!("{text}");
3737
}
3838

3939
if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) {
@@ -53,7 +53,7 @@ fn main() {
5353
let code = match run() {
5454
Ok(_) => 0,
5555
Err(ref e) => {
56-
write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail");
56+
write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail");
5757
1
5858
}
5959
};

crates/snapbox/src/cmd.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl OutputAssert {
496496

497497
use std::fmt::Write;
498498
let mut buf = String::new();
499-
writeln!(&mut buf, "{}", desc).unwrap();
499+
writeln!(&mut buf, "{desc}").unwrap();
500500
self.write_stdout(&mut buf).unwrap();
501501
self.write_stderr(&mut buf).unwrap();
502502
panic!("{}", buf);
@@ -526,7 +526,7 @@ impl OutputAssert {
526526

527527
use std::fmt::Write;
528528
let mut buf = String::new();
529-
writeln!(&mut buf, "{}", desc).unwrap();
529+
writeln!(&mut buf, "{desc}").unwrap();
530530
self.write_stdout(&mut buf).unwrap();
531531
self.write_stderr(&mut buf).unwrap();
532532
panic!("{}", buf);
@@ -548,7 +548,7 @@ impl OutputAssert {
548548

549549
use std::fmt::Write;
550550
let mut buf = String::new();
551-
writeln!(&mut buf, "{}", desc).unwrap();
551+
writeln!(&mut buf, "{desc}").unwrap();
552552
self.write_stdout(&mut buf).unwrap();
553553
self.write_stderr(&mut buf).unwrap();
554554
panic!("{}", buf);
@@ -580,7 +580,7 @@ impl OutputAssert {
580580

581581
use std::fmt::Write;
582582
let mut buf = String::new();
583-
writeln!(&mut buf, "{}", desc).unwrap();
583+
writeln!(&mut buf, "{desc}").unwrap();
584584
self.write_stdout(&mut buf).unwrap();
585585
self.write_stderr(&mut buf).unwrap();
586586
panic!("{}", buf);
@@ -761,7 +761,7 @@ pub fn display_exit_status(status: std::process::ExitStatus) -> String {
761761
libc::SIGTRAP => ", SIGTRAP: trace/breakpoint trap",
762762
_ => "",
763763
};
764-
Some(format!("signal: {}{}", signal, name))
764+
Some(format!("signal: {signal}{name}"))
765765
}
766766

767767
#[cfg(windows)]
@@ -914,8 +914,7 @@ pub(crate) mod examples {
914914
}
915915

916916
Err(crate::assert::Error::new(format!(
917-
"Unknown error building example {}",
918-
target_name
917+
"Unknown error building example {target_name}"
919918
)))
920919
}
921920

crates/snapbox/src/data/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub trait ToDebug {
3838

3939
impl<D: std::fmt::Debug> ToDebug for D {
4040
fn to_debug(&self) -> Data {
41-
Data::text(format!("{:#?}\n", self))
41+
Data::text(format!("{self:#?}\n"))
4242
}
4343
}
4444

crates/snapbox/src/filter/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ mod test {
625625
];
626626
for (line, pattern, expected) in cases {
627627
let actual = line_matches(line, pattern, &Redactions::new());
628-
assert_eq!(expected, actual, "line={:?} pattern={:?}", line, pattern);
628+
assert_eq!(expected, actual, "line={line:?} pattern={pattern:?}");
629629
}
630630
}
631631
}

crates/snapbox/src/filter/redactions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,14 @@ fn replace_many<'a>(
327327

328328
fn validate_placeholder(placeholder: &'static str) -> crate::assert::Result<&'static str> {
329329
if !placeholder.starts_with('[') || !placeholder.ends_with(']') {
330-
return Err(format!("Key `{}` is not enclosed in []", placeholder).into());
330+
return Err(format!("Key `{placeholder}` is not enclosed in []").into());
331331
}
332332

333333
if placeholder[1..(placeholder.len() - 1)]
334334
.find(|c: char| !c.is_ascii_uppercase() && c != '_')
335335
.is_some()
336336
{
337-
return Err(format!("Key `{}` can only be A-Z but ", placeholder).into());
337+
return Err(format!("Key `{placeholder}` can only be A-Z but ").into());
338338
}
339339

340340
Ok(placeholder)
@@ -356,7 +356,7 @@ mod test {
356356
];
357357
for (placeholder, expected) in cases {
358358
let actual = validate_placeholder(placeholder).is_ok();
359-
assert_eq!(expected, actual, "placeholder={:?}", placeholder);
359+
assert_eq!(expected, actual, "placeholder={placeholder:?}");
360360
}
361361
}
362362
}

crates/trycmd/src/bin/bin-fixture.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::process;
66

77
fn run() -> Result<(), Box<dyn Error>> {
88
if let Ok(text) = env::var("stdout") {
9-
println!("{}", text);
9+
println!("{text}");
1010
}
1111
if let Ok(text) = env::var("stderr") {
12-
eprintln!("{}", text);
12+
eprintln!("{text}");
1313
}
1414

1515
if env::var("echo_large").as_deref() == Ok("1") {
1616
for i in 0..(128 * 1024) {
17-
println!("{}", i);
17+
println!("{i}");
1818
}
1919
}
2020

@@ -31,7 +31,7 @@ fn run() -> Result<(), Box<dyn Error>> {
3131

3232
if let Ok(path) = env::var("cat") {
3333
let text = std::fs::read_to_string(path).unwrap();
34-
eprintln!("{}", text);
34+
eprintln!("{text}");
3535
}
3636

3737
if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) {
@@ -55,7 +55,7 @@ fn main() {
5555
let code = match run() {
5656
Ok(_) => 0,
5757
Err(ref e) => {
58-
write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail");
58+
write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail");
5959
1
6060
}
6161
};

crates/trycmd/src/runner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Case {
179179
Err(e) => {
180180
let output = Output::step(self.path.clone(), "setup".into());
181181
return vec![Err(
182-
output.error(format!("Failed to initialize sandbox: {}", e).into())
182+
output.error(format!("Failed to initialize sandbox: {e}").into())
183183
)];
184184
}
185185
};
@@ -283,7 +283,7 @@ impl Case {
283283
if let Err(err) = fs_context.close() {
284284
ok = false;
285285
output.fs.context.push(FileStatus::Failure(
286-
format!("Failed to cleanup sandbox: {}", err).into(),
286+
format!("Failed to cleanup sandbox: {err}").into(),
287287
));
288288
}
289289

@@ -758,7 +758,7 @@ impl std::fmt::Display for Stream {
758758
f,
759759
"{} {}:",
760760
self.stream,
761-
palette.error(format_args!("({})", msg))
761+
palette.error(format_args!("({msg})"))
762762
)?;
763763
writeln!(f, "{}", palette.info(&self.content))?;
764764
}

crates/trycmd/src/schema.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl TryCmd {
146146
}
147147
} else if ext == std::ffi::OsStr::new("trycmd") || ext == std::ffi::OsStr::new("md") {
148148
if stderr.is_some() && stderr != Some(&crate::Data::new()) {
149-
panic!("stderr should have been merged: {:?}", stderr);
149+
panic!("stderr should have been merged: {stderr:?}");
150150
}
151151
if let (Some(id), Some(stdout)) = (id, stdout) {
152152
let step = self
@@ -245,9 +245,7 @@ impl TryCmd {
245245
cmd_start = line_num;
246246
stdout_start = line_num + 1;
247247
} else {
248-
return Err(
249-
format!("Expected `$` on line {}, got `{}`", line_num, line).into()
250-
);
248+
return Err(format!("Expected `$` on line {line_num}, got `{line}`").into());
251249
}
252250
} else {
253251
break 'outer;
@@ -296,7 +294,7 @@ impl TryCmd {
296294

297295
let bin = loop {
298296
if cmdline.is_empty() {
299-
return Err(format!("No bin specified on line {}", cmd_start).into());
297+
return Err(format!("No bin specified on line {cmd_start}").into());
300298
}
301299
let next = cmdline.remove(0);
302300
if let Some((key, value)) = next.split_once('=') {
@@ -593,7 +591,7 @@ impl Step {
593591
) -> Result<snapbox::cmd::Command, crate::Error> {
594592
let bin = match &self.bin {
595593
Some(Bin::Path(path)) => Ok(path.clone()),
596-
Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {}", name).into()),
594+
Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {name}").into()),
597595
Some(Bin::Ignore) => Err("Internal error: tried to run an ignored bin".into()),
598596
Some(Bin::Error(err)) => Err(err.clone()),
599597
None => Err("No bin specified".into()),
@@ -895,7 +893,7 @@ impl std::str::FromStr for CommandStatus {
895893
_ => s
896894
.parse::<i32>()
897895
.map(Self::Code)
898-
.map_err(|_| crate::Error::new(format!("Expected an exit code, got {}", s))),
896+
.map_err(|_| crate::Error::new(format!("Expected an exit code, got {s}"))),
899897
}
900898
}
901899
}

0 commit comments

Comments
 (0)