From 6cf747678c49a2197d16174f62cf9a8c7b7fdf7d Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:06:42 +0100 Subject: [PATCH 01/14] Fix `clippy::needless_borrows_for_generic_args` warnings --- src/theme.rs | 2 +- tests/integration_tests.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index 11352183ed..5cd571f1c2 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -509,7 +509,7 @@ mod tests { ThemePreference::Light, ]; for pref in prefs { - assert_eq!(pref, ThemePreference::new(&pref.to_string())); + assert_eq!(pref, ThemePreference::new(pref.to_string())); } } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 436d84d567..3aafb17c94 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1832,7 +1832,7 @@ fn do_not_panic_regression_tests() { ] { bat() .arg("--color=always") - .arg(&format!("regression_tests/{filename}")) + .arg(format!("regression_tests/{filename}")) .assert() .success(); } @@ -1845,7 +1845,7 @@ fn do_not_detect_different_syntax_for_stdin_and_files() { let cmd_for_file = bat() .arg("--color=always") .arg("--map-syntax=*.js:Markdown") - .arg(&format!("--file-name={file}")) + .arg(format!("--file-name={file}")) .arg("--style=plain") .arg(file) .assert() @@ -1855,7 +1855,7 @@ fn do_not_detect_different_syntax_for_stdin_and_files() { .arg("--color=always") .arg("--map-syntax=*.js:Markdown") .arg("--style=plain") - .arg(&format!("--file-name={file}")) + .arg(format!("--file-name={file}")) .pipe_stdin(Path::new(EXAMPLES_DIR).join(file)) .unwrap() .assert() @@ -1874,7 +1874,7 @@ fn no_first_line_fallback_when_mapping_to_invalid_syntax() { bat() .arg("--color=always") .arg("--map-syntax=*.invalid-syntax:InvalidSyntax") - .arg(&format!("--file-name={file}")) + .arg(format!("--file-name={file}")) .arg("--style=plain") .arg(file) .assert() From b009fee5ea76dbdbcea02d656a6a3239a0f78d04 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:11:34 +0100 Subject: [PATCH 02/14] Fix `clippy::needless_return` warnings --- src/vscreen.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vscreen.rs b/src/vscreen.rs index 9e29f9cc36..af082cef05 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -360,10 +360,10 @@ pub struct EscapeSequenceOffsetsIterator<'a> { impl<'a> EscapeSequenceOffsetsIterator<'a> { pub fn new(text: &'a str) -> EscapeSequenceOffsetsIterator<'a> { - return EscapeSequenceOffsetsIterator { + EscapeSequenceOffsetsIterator { text, chars: text.char_indices().peekable(), - }; + } } /// Takes values from the iterator while the predicate returns true. @@ -564,10 +564,10 @@ pub struct EscapeSequenceIterator<'a> { impl<'a> EscapeSequenceIterator<'a> { pub fn new(text: &'a str) -> EscapeSequenceIterator<'a> { - return EscapeSequenceIterator { + EscapeSequenceIterator { text, offset_iter: EscapeSequenceOffsetsIterator::new(text), - }; + } } } From 3d442cdf98bd0ac12e91d541d82b4807b7678024 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:20:25 +0100 Subject: [PATCH 03/14] Fix `clippy::needless_borrow` warnings --- src/printer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/printer.rs b/src/printer.rs index 95017188c3..ab00a66e71 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -432,7 +432,7 @@ impl<'a> InteractivePrinter<'a> { .highlight_line(for_highlighting, highlighter_from_set.syntax_set)?; if too_long { - highlighted_line[0].1 = &line; + highlighted_line[0].1 = line; } Ok(highlighted_line) From 3d0f0c056552deb0ca080e3f09378997c1664d2a Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:14:29 +0100 Subject: [PATCH 04/14] Fix `clippy::unnecessary_map_or` warnings --- src/printer.rs | 6 +++--- src/syntax_mapping.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index ab00a66e71..04300acbb5 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -267,7 +267,7 @@ impl<'a> InteractivePrinter<'a> { let is_printing_binary = input .reader .content_type - .map_or(false, |c| c.is_binary() && !config.show_nonprintable); + .is_some_and(|c| c.is_binary() && !config.show_nonprintable); let needs_to_match_syntax = (!is_printing_binary || matches!(config.binary, BinaryBehavior::AsText)) @@ -544,7 +544,7 @@ impl<'a> Printer for InteractivePrinter<'a> { })?; if self.config.style_components.grid() { - if self.content_type.map_or(false, |c| c.is_text()) + if self.content_type.is_some_and(|c| c.is_text()) || self.config.show_nonprintable || matches!(self.config.binary, BinaryBehavior::AsText) { @@ -559,7 +559,7 @@ impl<'a> Printer for InteractivePrinter<'a> { fn print_footer(&mut self, handle: &mut OutputHandle, _input: &OpenedInput) -> Result<()> { if self.config.style_components.grid() - && (self.content_type.map_or(false, |c| c.is_text()) + && (self.content_type.is_some_and(|c| c.is_text()) || self.config.show_nonprintable || matches!(self.config.binary, BinaryBehavior::AsText)) { diff --git a/src/syntax_mapping.rs b/src/syntax_mapping.rs index a149f9bbe1..306443e6eb 100644 --- a/src/syntax_mapping.rs +++ b/src/syntax_mapping.rs @@ -153,7 +153,7 @@ impl<'a> SyntaxMapping<'a> { if glob.is_match_candidate(&candidate) || candidate_filename .as_ref() - .map_or(false, |filename| glob.is_match_candidate(filename)) + .is_some_and(|filename| glob.is_match_candidate(filename)) { return Some(*syntax); } From f0e2f642e04011b221a08ccf38213ce58cc82879 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:16:03 +0100 Subject: [PATCH 05/14] Fix `clippy::redundant_closure` warnings --- src/style.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style.rs b/src/style.rs index b8d8b09f00..d6343c94ba 100644 --- a/src/style.rs +++ b/src/style.rs @@ -225,7 +225,7 @@ impl FromStr for StyleComponentList { fn from_str(s: &str) -> Result { Ok(StyleComponentList( s.split(",") - .map(|s| ComponentAction::extract_from_str(s)) // If the component starts with "-", it's meant to be removed + .map(ComponentAction::extract_from_str) // If the component starts with "-", it's meant to be removed .map(|(a, s)| Ok((a, StyleComponent::from_str(s)?))) .collect::>>()?, )) From 2c49d905e433882c0cbc5c73c51a1df9781038a6 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:09:39 +0100 Subject: [PATCH 06/14] Fix `clippy::legacy_numeric_constants` warnings --- src/line_range.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/line_range.rs b/src/line_range.rs index 8899c70601..eb844435f4 100644 --- a/src/line_range.rs +++ b/src/line_range.rs @@ -9,8 +9,8 @@ pub struct LineRange { impl Default for LineRange { fn default() -> LineRange { LineRange { - lower: usize::min_value(), - upper: usize::max_value(), + lower: usize::MIN, + upper: usize::MAX, } } } @@ -93,7 +93,7 @@ fn test_parse_full() { #[test] fn test_parse_partial_min() { let range = LineRange::from(":50").expect("Shouldn't fail on test!"); - assert_eq!(usize::min_value(), range.lower); + assert_eq!(usize::MIN, range.lower); assert_eq!(50, range.upper); } @@ -101,7 +101,7 @@ fn test_parse_partial_min() { fn test_parse_partial_max() { let range = LineRange::from("40:").expect("Shouldn't fail on test!"); assert_eq!(40, range.lower); - assert_eq!(usize::max_value(), range.upper); + assert_eq!(usize::MAX, range.upper); } #[test] @@ -203,11 +203,7 @@ impl LineRanges { } pub fn from(ranges: Vec) -> LineRanges { - let largest_upper_bound = ranges - .iter() - .map(|r| r.upper) - .max() - .unwrap_or(usize::max_value()); + let largest_upper_bound = ranges.iter().map(|r| r.upper).max().unwrap_or(usize::MAX); LineRanges { ranges, largest_upper_bound, From cbc9c3629d72e7708805f8b3c1a5a4927ff66a39 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:18:33 +0100 Subject: [PATCH 07/14] Fix `clippy::manual_pattern_char_comparison` warnings --- src/printer.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 04300acbb5..abc84464bb 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -144,7 +144,7 @@ impl<'a> Printer for SimplePrinter<'a> { // Skip squeezed lines. if let Some(squeeze_limit) = self.config.squeeze_lines { if String::from_utf8_lossy(line_buffer) - .trim_end_matches(|c| c == '\r' || c == '\n') + .trim_end_matches(['\r', '\n']) .is_empty() { self.consecutive_empty_lines += 1; @@ -644,7 +644,7 @@ impl<'a> Printer for InteractivePrinter<'a> { // Skip squeezed lines. if let Some(squeeze_limit) = self.config.squeeze_lines { - if line.trim_end_matches(|c| c == '\r' || c == '\n').is_empty() { + if line.trim_end_matches(['\r', '\n']).is_empty() { self.consecutive_empty_lines += 1; if self.consecutive_empty_lines > squeeze_limit { return Ok(()); @@ -697,7 +697,7 @@ impl<'a> Printer for InteractivePrinter<'a> { // Regular text. EscapeSequence::Text(text) => { let text = self.preprocess(text, &mut cursor_total); - let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n'); + let text_trimmed = text.trim_end_matches(['\r', '\n']); write!( handle, @@ -751,10 +751,8 @@ impl<'a> Printer for InteractivePrinter<'a> { match chunk { // Regular text. EscapeSequence::Text(text) => { - let text = self.preprocess( - text.trim_end_matches(|c| c == '\r' || c == '\n'), - &mut cursor_total, - ); + let text = self + .preprocess(text.trim_end_matches(['\r', '\n']), &mut cursor_total); let mut max_width = cursor_max - cursor; From cc46282866bf73f4bd4af670af4823feb494986f Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:01:29 +0100 Subject: [PATCH 08/14] Fix `clippy::into_iter_on_ref` warnings --- src/bin/bat/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 8f69870f0a..d339ba948d 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -425,7 +425,7 @@ impl App { None => StyleComponents(HashSet::from_iter( StyleComponent::Default .components(self.interactive_output) - .into_iter() + .iter() .cloned(), )), }; From 095442191c18ab508b8166ad33699b4606017b1c Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:29:00 +0100 Subject: [PATCH 09/14] Fix `clippy::ptr_arg` warnings --- src/lessopen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lessopen.rs b/src/lessopen.rs index cf004d493e..4e18b85ac4 100644 --- a/src/lessopen.rs +++ b/src/lessopen.rs @@ -200,7 +200,7 @@ impl LessOpenPreprocessor { }) } - fn fall_back_to_original_file(&self, lessopen_stdout: &Vec, exit_code: ExitStatus) -> bool { + fn fall_back_to_original_file(&self, lessopen_stdout: &[u8], exit_code: ExitStatus) -> bool { lessopen_stdout.is_empty() && (!exit_code.success() || matches!(self.kind, LessOpenKind::PipedIgnoreExitCode)) } From 625e986552c3a75bef1228259c464afe8af3d511 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:22:01 +0100 Subject: [PATCH 10/14] Fix `clippy::manual_ignore_case_cmp` warnings --- src/assets/build_assets/acknowledgements.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets/build_assets/acknowledgements.rs b/src/assets/build_assets/acknowledgements.rs index c4fde91971..db9b5c69e1 100644 --- a/src/assets/build_assets/acknowledgements.rs +++ b/src/assets/build_assets/acknowledgements.rs @@ -60,7 +60,7 @@ fn to_path_and_stem(source_dir: &Path, entry: DirEntry) -> Option { fn handle_file(path_and_stem: &PathAndStem) -> Result> { if path_and_stem.stem == "NOTICE" { handle_notice(&path_and_stem.path) - } else if path_and_stem.stem.to_ascii_uppercase() == "LICENSE" { + } else if path_and_stem.stem.eq_ignore_ascii_case("LICENSE") { handle_license(&path_and_stem.path) } else { Ok(None) From bc24ce9ad442bc4586e814f1971d666ef70352a9 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:23:42 +0100 Subject: [PATCH 11/14] Fix `clippy::needless_update` warnings --- src/theme.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/theme.rs b/src/theme.rs index 5cd571f1c2..b2903b8665 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -383,7 +383,6 @@ mod tests { theme: ThemePreference::Fixed(ThemeName::Named("Theme".to_string())), theme_dark: Some(ThemeName::Named("Dark Theme".to_string())), theme_light: Some(ThemeName::Named("Light Theme".to_string())), - ..Default::default() }, ] { let detector = ConstantDetector(color_scheme); From 52252b15d699a0370e5aac7557c8af8409e09b0a Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sun, 2 Feb 2025 14:20:05 +0100 Subject: [PATCH 12/14] Fix `clippy::needless_lifetimes` warnings --- src/assets.rs | 2 +- src/controller.rs | 2 +- src/input.rs | 2 +- src/printer.rs | 6 +++--- src/syntax_mapping.rs | 2 +- src/vscreen.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index d32ccbd403..e6c5021995 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -370,7 +370,7 @@ mod tests { pub temp_dir: TempDir, } - impl<'a> SyntaxDetectionTest<'a> { + impl SyntaxDetectionTest<'_> { fn new() -> Self { SyntaxDetectionTest { assets: HighlightingAssets::from_binary(), diff --git a/src/controller.rs b/src/controller.rs index ffc5dd5b57..422b381ea1 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -25,7 +25,7 @@ pub struct Controller<'a> { preprocessor: Option, } -impl<'b> Controller<'b> { +impl Controller<'_> { pub fn new<'a>(config: &'a Config, assets: &'a HighlightingAssets) -> Controller<'a> { Controller { config, diff --git a/src/input.rs b/src/input.rs index 0ebaa4cead..b36204df8c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -75,7 +75,7 @@ pub(crate) enum InputKind<'a> { CustomReader(Box), } -impl<'a> InputKind<'a> { +impl InputKind<'_> { pub fn description(&self) -> InputDescription { match self { InputKind::OrdinaryFile(ref path) => InputDescription::new(path.to_string_lossy()), diff --git a/src/printer.rs b/src/printer.rs index abc84464bb..2c364bd7dd 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -73,7 +73,7 @@ pub enum OutputHandle<'a> { FmtWrite(&'a mut dyn fmt::Write), } -impl<'a> OutputHandle<'a> { +impl OutputHandle<'_> { fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<()> { match self { Self::IoWrite(handle) => handle.write_fmt(args).map_err(Into::into), @@ -116,7 +116,7 @@ impl<'a> SimplePrinter<'a> { } } -impl<'a> Printer for SimplePrinter<'a> { +impl Printer for SimplePrinter<'_> { fn print_header( &mut self, _handle: &mut OutputHandle, @@ -448,7 +448,7 @@ impl<'a> InteractivePrinter<'a> { } } -impl<'a> Printer for InteractivePrinter<'a> { +impl Printer for InteractivePrinter<'_> { fn print_header( &mut self, handle: &mut OutputHandle, diff --git a/src/syntax_mapping.rs b/src/syntax_mapping.rs index 306443e6eb..0cd2d655d1 100644 --- a/src/syntax_mapping.rs +++ b/src/syntax_mapping.rs @@ -61,7 +61,7 @@ pub struct SyntaxMapping<'a> { halt_glob_build: Arc, } -impl<'a> Drop for SyntaxMapping<'a> { +impl Drop for SyntaxMapping<'_> { fn drop(&mut self) { // signal the offload thread to halt early self.halt_glob_build.store(true, Ordering::Relaxed); diff --git a/src/vscreen.rs b/src/vscreen.rs index af082cef05..06cc038ac8 100644 --- a/src/vscreen.rs +++ b/src/vscreen.rs @@ -539,7 +539,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> { } } -impl<'a> Iterator for EscapeSequenceOffsetsIterator<'a> { +impl Iterator for EscapeSequenceOffsetsIterator<'_> { type Item = EscapeSequenceOffsets; fn next(&mut self) -> Option { match self.chars.peek() { From 53af1dc32d507daf4ecdce9639e52f6e9dbbfd04 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:26:00 +0100 Subject: [PATCH 13/14] Fix `clippy::unnecessary_filter_map` warnings --- tests/github-actions.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/github-actions.rs b/tests/github-actions.rs index c902f10bfd..d697ddf8c7 100644 --- a/tests/github-actions.rs +++ b/tests/github-actions.rs @@ -35,13 +35,7 @@ fn all_jobs_not_missing_any_jobs() { .as_mapping() .unwrap() .keys() - .filter_map(|k| { - if exceptions.contains(&k.as_str().unwrap_or_default()) { - None - } else { - Some(k) - } - }) + .filter(|k| !exceptions.contains(&k.as_str().unwrap_or_default())) .map(ToOwned::to_owned) .collect::>(); From 71dce0e7f3b5f36ed23fdb7f6220cb00a625d2a3 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Thu, 30 Jan 2025 18:30:20 +0100 Subject: [PATCH 14/14] Fix `clippy::duplicated_attributes` warnings --- src/lessopen.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lessopen.rs b/src/lessopen.rs index 4e18b85ac4..79f977afb1 100644 --- a/src/lessopen.rs +++ b/src/lessopen.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "lessopen")] - use std::convert::TryFrom; use std::env; use std::fs::File;