From 038e0622286a929be3ea41c881be77c6d17e003f Mon Sep 17 00:00:00 2001 From: Christopher Chang <51393127+chriscerie@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:25:34 -0800 Subject: [PATCH] Fix pedantic clippy --- selene-lib/src/lints.rs | 9 ++++++--- selene-lib/src/lints/test_util.rs | 2 +- selene/src/main.rs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/selene-lib/src/lints.rs b/selene-lib/src/lints.rs index d3ba8989..6f3a1584 100644 --- a/selene-lib/src/lints.rs +++ b/selene-lib/src/lints.rs @@ -137,7 +137,7 @@ impl Diagnostic { if suggestion_str.is_empty() { "consider removing this".to_string() } else { - format!("try: `{}`", suggestion_str) + format!("try: `{suggestion_str}`") }, ); } @@ -196,14 +196,17 @@ impl Diagnostic { } } + #[must_use] pub fn start_position(&self) -> u32 { self.primary_label.range.0 } + #[must_use] pub fn has_machine_applicable_fix(&self) -> bool { self.suggestion.is_some() && self.applicability == Applicability::MachineApplicable } + #[must_use] pub fn has_maybe_incorrect_fix(&self) -> bool { self.suggestion.is_some() && self.applicability == Applicability::MaybeIncorrect } @@ -211,13 +214,13 @@ impl Diagnostic { /// After applying suggestions, calls `get_new_diagnostics` and reruns to ensure fixes didn't produce new errors pub fn get_applied_suggestions_code( code: &str, - diagnostics: Vec<&Diagnostic>, + diagnostics: &[&Diagnostic], get_new_diagnostics: F, ) -> String where F: Fn(&str) -> Vec, { - let mut chosen_diagnostics = Self::get_independent_suggestions(&diagnostics); + let mut chosen_diagnostics = Self::get_independent_suggestions(diagnostics); let mut owned_diagnostics_ref; let mut owned_diagnostics; diff --git a/selene-lib/src/lints/test_util.rs b/selene-lib/src/lints/test_util.rs index 5216d385..c4b2d7c8 100644 --- a/selene-lib/src/lints/test_util.rs +++ b/selene-lib/src/lints/test_util.rs @@ -142,7 +142,7 @@ pub fn test_lint_config_with_output< suggestion = Diagnostic::get_applied_suggestions_code( suggestion.as_str(), - fixed_diagnostics, + &fixed_diagnostics, |new_code| { let fixed_ast = full_moon::parse(new_code).unwrap_or_else(|_| { panic!( diff --git a/selene/src/main.rs b/selene/src/main.rs index 3a640bf8..98f490f5 100644 --- a/selene/src/main.rs +++ b/selene/src/main.rs @@ -297,7 +297,7 @@ fn read( suggestion = Diagnostic::get_applied_suggestions_code( suggestion.as_str(), - diagnostics + &diagnostics .iter() .filter(|diagnostic| diagnostic.diagnostic.has_machine_applicable_fix()) .map(|diagnostic| &diagnostic.diagnostic)