Skip to content

Commit b7480a7

Browse files
committed
fix clippy warnings reported from rules that were newly enabled in Rust 1.88
1 parent 9f4e149 commit b7480a7

File tree

10 files changed

+50
-61
lines changed

10 files changed

+50
-61
lines changed

assets/builder/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ const THEME_PATHS: &[&str] = &[
3737
const THEME_BIN_PATH: &str = "../themes.bin";
3838

3939
fn main() {
40-
println!("Building theme set for syntect-printer: {}", THEME_BIN_PATH);
40+
println!("Building theme set for syntect-printer: {THEME_BIN_PATH}");
4141

4242
let mut set = ThemeSet::new();
4343

4444
for path in THEME_PATHS {
4545
let path = PathBuf::from_slash(path);
46-
println!("Loading theme from {:?}", path);
46+
println!("Loading theme from {path:?}");
4747

4848
let name = path.file_stem().and_then(OsStr::to_str).expect("File stem was not found in .tmTheme file. Did you specify incorrect file in THEME_PATHS?");
4949
let theme = ThemeSet::get_theme(&path).expect("Theme file was not found. Did you forget fetching submodules in ./submodules directory?");
5050
set.themes.insert(name.to_string(), theme);
5151

52-
println!("Loaded theme from {:?}", path);
52+
println!("Loaded theme from {path:?}");
5353
}
5454

5555
println!("Compressing theme set");
@@ -68,5 +68,5 @@ fn main() {
6868
fs::write(PathBuf::from_slash(THEME_BIN_PATH), &buf)
6969
.expect("Could not write compressed theme set");
7070

71-
println!("Built successfully: {}", THEME_BIN_PATH);
71+
println!("Built successfully: {THEME_BIN_PATH}");
7272
}

bench/benches/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn prepare() -> Vec<u8> {
1717
if line.ends_with('*') {
1818
let l = idx + 1;
1919
let s = path.as_os_str().to_str().unwrap();
20-
buf += &format!("{}:{}: {}\n", s, l, line);
20+
buf += &format!("{s}:{l}: {line}\n");
2121
}
2222
}
2323
}

src/bat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'main> BatPrinter<'main> {
9999
let mut themes: Vec<_> = self.assets.themes().collect();
100100
themes.sort_unstable();
101101
for theme in themes.into_iter() {
102-
println!("\x1b[1m{:?}\x1b[0m", theme);
102+
println!("\x1b[1m{theme:?}\x1b[0m");
103103
self.config.theme = theme.to_string();
104104
self.print(sample.clone())?;
105105
println!();

src/broken_pipe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mod tests {
4343

4444
#[test]
4545
fn test_io_do_not_ignore_other_errors() {
46-
let err = Error::new(io::ErrorKind::Other, "oops");
46+
let err = Error::other("oops");
4747
let res = io::Result::<i32>::Err(err);
4848
let res = res.ignore_broken_pipe();
4949
res.unwrap_err();
@@ -66,7 +66,7 @@ mod tests {
6666

6767
#[test]
6868
fn test_anyhow_do_not_ignore_other_io_error() {
69-
let err = Error::new(io::ErrorKind::Other, "oops");
69+
let err = Error::other("oops");
7070
let res = anyhow::Result::<i32>::Err(err.into());
7171
let res = res.ignore_broken_pipe();
7272
res.unwrap_err();

src/chunk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<I: Iterator<Item = Result<GrepMatch>>> Files<I> {
220220

221221
for (line, lnum) in lines {
222222
last_lnum = Some(lnum);
223-
assert!(lnum <= after_end, "line {} > chunk {}", lnum, after_end);
223+
assert!(lnum <= after_end, "line {lnum} > chunk {after_end}");
224224

225225
let in_before = before_start <= lnum && lnum < before_end;
226226
let in_after = after_start < lnum && lnum <= after_end;
@@ -279,7 +279,7 @@ impl<I: Iterator<Item = Result<GrepMatch>>> Iterator for Files<I> {
279279
Err(e) => return self.error_item(e),
280280
};
281281
let contents = match fs::read(&path)
282-
.with_context(|| format!("Could not open the matched file {:?}", path))
282+
.with_context(|| format!("Could not open the matched file {path:?}"))
283283
{
284284
Ok(vec) => decode_text(vec, self.encoding),
285285
Err(err) => return self.error_item(err),
@@ -535,7 +535,7 @@ mod tests {
535535
.unwrap()
536536
.collect::<Result<Vec<_>>>()
537537
.unwrap_err();
538-
assert_eq!(format!("{}", err), "dummy error!");
538+
assert_eq!(format!("{err}"), "dummy error!");
539539
}
540540
}
541541

src/grep.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ fn test_read_error() {
182182
for (got, expected) in msgs.iter().zip(expected.iter()) {
183183
assert!(
184184
got.contains(expected),
185-
"expected {:?} is included in {:?}",
186-
expected,
187-
got
185+
"expected {expected:?} is included in {got:?}"
188186
);
189187
}
190188
}

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,9 @@ fn main() {
781781
Ok(true) => 0,
782782
Ok(false) => 1,
783783
Err(err) => {
784-
eprintln!("\x1b[1;91merror:\x1b[0m {}", err);
784+
eprintln!("\x1b[1;91merror:\x1b[0m {err}");
785785
for err in err.chain().skip(1) {
786-
eprintln!(" Caused by: {}", err);
786+
eprintln!(" Caused by: {err}");
787787
}
788788
2
789789
}
@@ -983,7 +983,7 @@ mod tests {
983983
&["--generate-completion-script", "unknown-shell"][..],
984984
] {
985985
let parsed = command().try_get_matches_from(args);
986-
assert!(parsed.is_err(), "args: {:?}", args);
986+
assert!(parsed.is_err(), "args: {args:?}");
987987
}
988988
}
989989
}
@@ -1115,7 +1115,7 @@ mod tests {
11151115
for shell in COMPLETION_SHELLS {
11161116
let mut v = vec![];
11171117
generate_completion_script(shell, &mut v);
1118-
assert!(!v.is_empty(), "shell: {}", shell);
1118+
assert!(!v.is_empty(), "shell: {shell}");
11191119
}
11201120
}
11211121

@@ -1190,7 +1190,7 @@ mod tests {
11901190
env::set_var(OPTS_ENV_VAR, "'-i");
11911191

11921192
let err = Args::new().unwrap_err();
1193-
let msg = format!("{}", err);
1193+
let msg = format!("{err}");
11941194
assert!(
11951195
msg.contains("cannot be parsed as a shell command"),
11961196
"{msg:?}",
@@ -1208,7 +1208,7 @@ mod tests {
12081208
env::set_var(OPTS_ENV_VAR, OsStr::from_bytes(b"\xc3\x28"));
12091209

12101210
let err = Args::new().unwrap_err();
1211-
let msg = format!("{}", err);
1211+
let msg = format!("{err}");
12121212
assert!(msg.contains("is not a valid UTF-8 sequence"), "{msg:?}");
12131213
}
12141214
}

src/ripgrep.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn parse_size(input: &str) -> Result<u64> {
3636

3737
let u: u64 = input
3838
.parse()
39-
.with_context(|| format!("Could not parse {:?} as unsigned integer", input))?;
39+
.with_context(|| format!("Could not parse {input:?} as unsigned integer"))?;
4040

4141
Ok(u * mag)
4242
}
@@ -304,11 +304,11 @@ impl<'main> Config<'main> {
304304
Ok(if self.fixed_strings {
305305
let mut s = regex_syntax::escape(pat);
306306
if self.line_regexp {
307-
s = format!("^(?:{})$", s);
307+
s = format!("^(?:{s})$");
308308
}
309309
builder.build(&s)?
310310
} else if self.line_regexp {
311-
builder.build(&format!("^(?:{})$", pat))?
311+
builder.build(&format!("^(?:{pat})$"))?
312312
} else {
313313
builder.build(pat)?
314314
})
@@ -339,7 +339,7 @@ impl<'main> Config<'main> {
339339
}
340340

341341
if self.line_regexp {
342-
Ok(builder.build(&format!("^(?:{})$", pat))?)
342+
Ok(builder.build(&format!("^(?:{pat})$"))?)
343343
} else {
344344
Ok(builder.build(pat)?)
345345
}
@@ -526,7 +526,7 @@ impl<M: Matcher> Sink for Matches<'_, M> {
526526
ranges.push((m.start(), m.end()));
527527
true
528528
})
529-
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))?;
529+
.map_err(|e| io::Error::other(format!("{e}")))?;
530530
let mut regions = LineRegions::new(&ranges);
531531

532532
let mut line_number = line_number;
@@ -693,7 +693,7 @@ mod tests {
693693
for input in inputs.iter() {
694694
let mut printer = DummyPrinter::default();
695695
let pat = r"\*$";
696-
let file = dir.join(format!("{}.in", input));
696+
let file = dir.join(format!("{input}.in"));
697697
let paths = iter::once(file.as_path());
698698
let found = grep(&printer, pat, Some(paths), Config::new(3, 6)).unwrap();
699699
let expected = read_expected_chunks(&dir, input)
@@ -717,7 +717,7 @@ mod tests {
717717
let pat = r"\*$";
718718
let paths = inputs
719719
.iter()
720-
.map(|s| dir.join(format!("{}.in", s)).into_os_string())
720+
.map(|s| dir.join(format!("{s}.in")).into_os_string())
721721
.collect::<Vec<_>>();
722722
let paths = paths.iter().map(AsRef::as_ref);
723723

@@ -743,8 +743,8 @@ mod tests {
743743
let pat = "^this does not match to any line!!!!!!$";
744744
let found = grep(&printer, pat, Some(paths), Config::new(3, 6)).unwrap();
745745
let files = printer.0.into_inner().unwrap();
746-
assert!(!found, "result: {:?}", files);
747-
assert!(files.is_empty(), "result: {:?}", files);
746+
assert!(!found, "result: {files:?}");
747+
assert!(files.is_empty(), "result: {files:?}");
748748
}
749749

750750
#[test]
@@ -776,7 +776,7 @@ mod tests {
776776
let paths = iter::once(path.as_path());
777777
let pat = ".*";
778778
let err = grep(ErrorPrinter, pat, Some(paths), Config::new(3, 6)).unwrap_err();
779-
let msg = format!("{}", err);
779+
let msg = format!("{err}");
780780
assert_eq!(msg, "dummy error");
781781
}
782782

@@ -789,7 +789,7 @@ mod tests {
789789

790790
let re = Regex::new(r"^\x1b\[1m\w+\x1b\[0m: .+(, .+)*$").unwrap();
791791
for line in output.lines() {
792-
assert!(re.is_match(line), "{:?} did not match to {:?}", line, re);
792+
assert!(re.is_match(line), "{line:?} did not match to {re:?}");
793793
}
794794
}
795795

@@ -803,8 +803,7 @@ mod tests {
803803
let chunks_line = lines.next().unwrap();
804804
assert!(
805805
chunks_line.starts_with("# chunks: "),
806-
"actual={:?}",
807-
chunks_line
806+
"actual={chunks_line:?}"
808807
);
809808
let chunks_line = &chunks_line["# chunks: ".len()..];
810809
for chunk in chunks_line.split(", ") {
@@ -820,8 +819,7 @@ mod tests {
820819
let matches_line = lines.next().unwrap();
821820
assert!(
822821
matches_line.starts_with("# lines: "),
823-
"actual={:?}",
824-
matches_line
822+
"actual={matches_line:?}"
825823
);
826824
let matches_line = &matches_line["# lines: ".len()..];
827825
for mat in matches_line.split(", ") {
@@ -849,7 +847,7 @@ mod tests {
849847
f(&mut config);
850848

851849
let found = grep(&printer, pat, Some(paths), config).unwrap();
852-
assert!(found, "file={}", file);
850+
assert!(found, "file={file}");
853851

854852
let mut files = printer.0.into_inner().unwrap();
855853
assert_eq!(files.len(), 1, "file={}", file);
@@ -1027,19 +1025,12 @@ mod tests {
10271025
),
10281026
Err(want) => {
10291027
let err = err.unwrap_or_else(|| {
1030-
panic!(
1031-
"wanted error {:?} but no error for {:?} ({})",
1032-
want, input, opt
1033-
)
1028+
panic!("wanted error {want:?} but no error for {input:?} ({opt})")
10341029
});
1035-
let msg = format!("{}", err);
1030+
let msg = format!("{err}");
10361031
assert!(
10371032
msg.contains(want),
1038-
"wanted error {:?} but got {:?} for {:?} ({})",
1039-
want,
1040-
msg,
1041-
input,
1042-
opt,
1033+
"wanted error {want:?} but got {msg:?} for {input:?} ({opt})",
10431034
);
10441035
}
10451036
}

src/syntect.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn list_themes_with_syntaxes<W: Write>(
7070
.try_for_each(|(name, theme)| -> Result<()> {
7171
let mut drawer = Drawer::new(&mut out, opts, theme, &sample_file.chunks);
7272
drawer.canvas.set_bold()?;
73-
write!(drawer.canvas, "{:?}", name)?;
73+
write!(drawer.canvas, "{name:?}")?;
7474
drawer.canvas.draw_newline()?;
7575
drawer.canvas.draw_sample()?;
7676
writeln!(drawer.canvas)?;
@@ -521,7 +521,7 @@ impl<W: Write> Canvas<W> {
521521

522522
fn draw_sample_row(&mut self, colors: &[(&str, Color)]) -> io::Result<()> {
523523
for (name, color) in colors {
524-
write!(self.out, " {} ", name)?;
524+
write!(self.out, " {name} ")?;
525525
self.set_bg(*color)?;
526526
self.out.write_all(b" \x1b[0m")?;
527527
}
@@ -675,7 +675,7 @@ impl<'file, W: Write> Drawer<'file, W> {
675675
let width = num_digits(lnum);
676676
self.canvas
677677
.draw_spaces((self.lnum_width - width) as usize)?;
678-
write!(self.canvas, " {}", lnum)?;
678+
write!(self.canvas, " {lnum}")?;
679679
if self.grid {
680680
if matched {
681681
self.canvas.set_gutter_color()?;
@@ -795,7 +795,7 @@ impl<'file, W: Write> Drawer<'file, W> {
795795
self.draw_text_wrappping(matched, events.current_style, events.in_region)?;
796796
width = 0;
797797
}
798-
write!(self.canvas, "{}", c)?;
798+
write!(self.canvas, "{c}")?;
799799
width += w;
800800
}
801801
DrawEvent::TokenBoundary(prev_style) => {
@@ -880,7 +880,7 @@ impl<'file, W: Write> Drawer<'file, W> {
880880
let path = path.as_os_str().to_string_lossy();
881881
self.canvas.set_default_fg()?;
882882
self.canvas.set_bold()?;
883-
write!(self.canvas, " {}", path)?;
883+
write!(self.canvas, " {path}")?;
884884
if self.canvas.has_background {
885885
self.canvas
886886
.fill_spaces(path.width_cjk() + 1, self.term_width as usize)?;
@@ -1272,8 +1272,8 @@ mod tests {
12721272
if input.starts_with("test_") {
12731273
input = &input["test_".len()..];
12741274
}
1275-
let infile = dir.join(format!("{}.rs", input));
1276-
let outfile = dir.join(format!("{}.out", input));
1275+
let infile = dir.join(format!("{input}.rs"));
1276+
let outfile = dir.join(format!("{input}.out"));
12771277
let file = read_chunks(infile);
12781278
run_uitest(file, outfile, f);
12791279
}
@@ -1435,7 +1435,7 @@ mod tests {
14351435
if input.starts_with("test_") {
14361436
input = &input["test_".len()..];
14371437
}
1438-
let file = format!("list_themes_{}.out", input);
1438+
let file = format!("list_themes_{input}.out");
14391439
let expected = Path::new("testdata").join("syntect").join(file);
14401440
let expected = fs::read(expected).unwrap();
14411441

@@ -1522,7 +1522,7 @@ mod tests {
15221522
let printer =
15231523
SyntectPrinter::with_assets(ASSETS.clone(), ErrorStdout(io::ErrorKind::Other), opts);
15241524
let err = printer.print(file).unwrap_err();
1525-
assert_eq!(&format!("{}", err), "dummy error!", "message={}", err);
1525+
assert_eq!(&format!("{err}"), "dummy error!", "message={err}");
15261526
}
15271527

15281528
#[test]
@@ -1547,8 +1547,8 @@ mod tests {
15471547
Err(e) => e,
15481548
Ok(_) => panic!("error did not occur"),
15491549
};
1550-
let msg = format!("{}", err);
1551-
assert!(msg.contains("Unknown theme"), "message={:?}", msg);
1550+
let msg = format!("{err}");
1551+
assert!(msg.contains("Unknown theme"), "message={msg:?}");
15521552
}
15531553

15541554
#[test]
@@ -1626,7 +1626,7 @@ mod tests {
16261626
&ASSETS.syntax_set,
16271627
)
16281628
.unwrap_err();
1629-
assert_eq!(&format!("{}", err), "dummy error!", "message={}", err);
1629+
assert_eq!(&format!("{err}"), "dummy error!", "message={err}");
16301630
}
16311631

16321632
#[test]

0 commit comments

Comments
 (0)