Skip to content

Commit 4bdee80

Browse files
committed
style: simplify string formatting for readability
1 parent 3d0d186 commit 4bdee80

File tree

9 files changed

+24
-25
lines changed

9 files changed

+24
-25
lines changed

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
Some(true) => {}
66
// rustc version too small or can't figure it out
77
_ => {
8-
eprintln!("'fd' requires rustc >= {}", min_version);
8+
eprintln!("'fd' requires rustc >= {min_version}");
99
std::process::exit(1);
1010
}
1111
}

src/exec/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn handle_cmd_error(cmd: Option<&Command>, err: io::Error) -> ExitCode {
103103
ExitCode::GeneralError
104104
}
105105
(_, err) => {
106-
print_error(format!("Problem while executing command: {}", err));
106+
print_error(format!("Problem while executing command: {err}"));
107107
ExitCode::GeneralError
108108
}
109109
}

src/filter/time.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ mod tests {
149149
// Timestamp only supported via '@' prefix
150150
assert!(TimeFilter::before(&ref_time, &ref_timestamp.to_string()).is_none());
151151
assert!(
152-
TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
152+
TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))
153153
.unwrap()
154154
.applies_to(&t1m_ago)
155155
);
156156
assert!(
157-
!TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
157+
!TimeFilter::before(&ref_time, &format!("@{ref_timestamp}"))
158158
.unwrap()
159159
.applies_to(&t1s_later)
160160
);
161161
assert!(
162-
!TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
162+
!TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))
163163
.unwrap()
164164
.applies_to(&t1m_ago)
165165
);
166-
assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
166+
assert!(TimeFilter::after(&ref_time, &format!("@{ref_timestamp}"))
167167
.unwrap()
168168
.applies_to(&t1s_later));
169169
}

src/hyperlink.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn encode(f: &mut Formatter, byte: u8) -> fmt::Result {
3535
#[cfg(windows)]
3636
b'\\' => f.write_char('/'),
3737
_ => {
38-
write!(f, "%{:02X}", byte)
38+
write!(f, "%{byte:02X}")
3939
}
4040
}
4141
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() {
6363
exit_code.exit();
6464
}
6565
Err(err) => {
66-
eprintln!("[fd error]: {:#}", err);
66+
eprintln!("[fd error]: {err:#}");
6767
ExitCode::GeneralError.exit();
6868
}
6969
}

src/output.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn print_entry<W: Write>(stdout: &mut W, entry: &DirEntry, config: &Config)
1717
let mut has_hyperlink = false;
1818
if config.hyperlink {
1919
if let Some(url) = PathUrl::new(entry.path()) {
20-
write!(stdout, "\x1B]8;;{}\x1B\\", url)?;
20+
write!(stdout, "\x1B]8;;{url}\x1B\\")?;
2121
has_hyperlink = true;
2222
}
2323
}
@@ -143,7 +143,7 @@ fn print_entry_uncolorized_base<W: Write>(
143143
if let Some(ref separator) = config.path_separator {
144144
*path_string.to_mut() = replace_path_separator(&path_string, separator);
145145
}
146-
write!(stdout, "{}", path_string)?;
146+
write!(stdout, "{path_string}")?;
147147
print_trailing_slash(stdout, entry, config, None)
148148
}
149149

src/walk.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a, W: Write> ReceiverBuffer<'a, W> {
252252
fn print(&mut self, entry: &DirEntry) -> Result<(), ExitCode> {
253253
if let Err(e) = output::print_entry(&mut self.stdout, entry, self.config) {
254254
if e.kind() != ::std::io::ErrorKind::BrokenPipe {
255-
print_error(format!("Could not write to output: {}", e));
255+
print_error(format!("Could not write to output: {e}"));
256256
return Err(ExitCode::GeneralError);
257257
}
258258
}
@@ -377,8 +377,7 @@ impl WorkerState {
377377
Some(ignore::Error::Partial(_)) => (),
378378
Some(err) => {
379379
print_error(format!(
380-
"Malformed pattern in global ignore file. {}.",
381-
err
380+
"Malformed pattern in global ignore file. {err}."
382381
));
383382
}
384383
None => (),
@@ -392,7 +391,7 @@ impl WorkerState {
392391
match result {
393392
Some(ignore::Error::Partial(_)) => (),
394393
Some(err) => {
395-
print_error(format!("Malformed pattern in custom ignore file. {}.", err));
394+
print_error(format!("Malformed pattern in custom ignore file. {err}."));
396395
}
397396
None => (),
398397
}

tests/testenv/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ fn format_output_error(args: &[&str], expected: &str, actual: &str) -> String {
104104
let diff_text = diff::lines(expected, actual)
105105
.into_iter()
106106
.map(|diff| match diff {
107-
diff::Result::Left(l) => format!("-{}", l),
108-
diff::Result::Both(l, _) => format!(" {}", l),
109-
diff::Result::Right(r) => format!("+{}", r),
107+
diff::Result::Left(l) => format!("-{l}"),
108+
diff::Result::Both(l, _) => format!(" {l}"),
109+
diff::Result::Right(r) => format!("+{r}"),
110110
})
111111
.collect::<Vec<_>>()
112112
.join("\n");
@@ -290,7 +290,7 @@ impl TestEnv {
290290
pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {
291291
let status = self.assert_error_subdirectory(".", args, Some(expected));
292292
if status.success() {
293-
panic!("error '{}' did not occur.", expected);
293+
panic!("error '{expected}' did not occur.");
294294
}
295295
}
296296

tests/tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn test_full_path() {
597597
te.assert_output(
598598
&[
599599
"--full-path",
600-
&format!("^{prefix}.*three.*foo$", prefix = prefix),
600+
&format!("^{prefix}.*three.*foo$"),
601601
],
602602
"one/two/three/d.foo
603603
one/two/three/directory_foo/",
@@ -1518,7 +1518,7 @@ fn test_symlink_as_absolute_root() {
15181518
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
15191519

15201520
te.assert_output(
1521-
&["", &format!("{abs_path}/symlink", abs_path = abs_path)],
1521+
&["", &format!("{abs_path}/symlink")],
15221522
&format!(
15231523
"{abs_path}/symlink/c.foo
15241524
{abs_path}/symlink/C.Foo2
@@ -1543,7 +1543,7 @@ fn test_symlink_and_full_path() {
15431543
&[
15441544
"--absolute-path",
15451545
"--full-path",
1546-
&format!("^{prefix}.*three", prefix = prefix),
1546+
&format!("^{prefix}.*three"),
15471547
],
15481548
&format!(
15491549
"{abs_path}/{expected_path}/three/
@@ -1563,8 +1563,8 @@ fn test_symlink_and_full_path_abs_path() {
15631563
te.assert_output(
15641564
&[
15651565
"--full-path",
1566-
&format!("^{prefix}.*symlink.*three", prefix = prefix),
1567-
&format!("{abs_path}/symlink", abs_path = abs_path),
1566+
&format!("^{prefix}.*symlink.*three"),
1567+
&format!("{abs_path}/symlink"),
15681568
],
15691569
&format!(
15701570
"{abs_path}/symlink/three/
@@ -2337,7 +2337,7 @@ fn test_owner_current_user() {
23372337
fn test_owner_current_group() {
23382338
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
23392339
let gid = Gid::current();
2340-
te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");
2340+
te.assert_output(&["--owner", &format!(":{gid}"), "a.foo"], "a.foo");
23412341
if let Ok(Some(group)) = Group::from_gid(gid) {
23422342
te.assert_output(&["--owner", &format!(":{}", group.name), "a.foo"], "a.foo");
23432343
}
@@ -2616,7 +2616,7 @@ fn test_invalid_cwd() {
26162616
.unwrap();
26172617

26182618
if !output.status.success() {
2619-
panic!("{:?}", output);
2619+
panic!("{output:?}");
26202620
}
26212621
}
26222622

0 commit comments

Comments
 (0)