From ca20c5a1123c3185811712a820ad79e34137d98b Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 11 Apr 2024 09:47:41 -0400 Subject: [PATCH] Fix clippy complaints --- src/analyzer/stmt/if_analyzer.rs | 13 +++++-------- src/analyzer/stmt_analyzer.rs | 15 +++++++-------- src/code_info/issue.rs | 13 +++++++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/analyzer/stmt/if_analyzer.rs b/src/analyzer/stmt/if_analyzer.rs index 1a157396..8b6200b4 100644 --- a/src/analyzer/stmt/if_analyzer.rs +++ b/src/analyzer/stmt/if_analyzer.rs @@ -46,26 +46,23 @@ pub(crate) fn analyze( .iter() .any(|clause| !clause.possibilities.is_empty()) { - let mut omit_keys = + let omit_keys = outer_context .clauses .iter() .fold(FxHashSet::default(), |mut acc, clause| { - acc.extend(clause.possibilities.keys().collect::>()); + acc.extend(clause.possibilities.keys()); acc }); - let (dont_omit_keys, _) = hakana_algebra::get_truths_from_formula( + let (outer_context_truths, _) = hakana_algebra::get_truths_from_formula( outer_context.clauses.iter().map(|v| &**v).collect(), None, &mut FxHashSet::default(), ); - let dont_omit_keys = dont_omit_keys.keys().collect::>(); - - omit_keys.retain(|k| !dont_omit_keys.contains(k)); - - cond_referenced_var_ids.retain(|k| !omit_keys.contains(k)); + cond_referenced_var_ids + .retain(|k| !omit_keys.contains(k) || outer_context_truths.contains_key(k)); } // if the if has an || in the conditional, we cannot easily reason about it diff --git a/src/analyzer/stmt_analyzer.rs b/src/analyzer/stmt_analyzer.rs index a3647ee4..288ca1f2 100644 --- a/src/analyzer/stmt_analyzer.rs +++ b/src/analyzer/stmt_analyzer.rs @@ -273,7 +273,7 @@ fn detect_unused_statement_expressions( stmt: &aast::Stmt<(), ()>, context: &mut ScopeContext, ) { - if has_unused_must_use(&boxed, &statements_analyzer, &stmt, context) { + if has_unused_must_use(boxed, statements_analyzer) { analysis_data.maybe_add_issue( Issue::new( IssueKind::UnusedFunctionCall, @@ -406,8 +406,6 @@ fn detect_unused_statement_expressions( fn has_unused_must_use( boxed: &aast::Expr<(), ()>, statements_analyzer: &StatementsAnalyzer, - stmt: &aast::Stmt<(), ()>, - context: &mut ScopeContext, ) -> bool { match &boxed.2 { aast::Expr_::Call(boxed_call) => { @@ -420,9 +418,10 @@ fn has_unused_must_use( // For statements like "Asio\join(some_fn());" // Asio\join does not count as "using" the value if function_id == StrId::ASIO_JOIN { - return boxed_call.args.iter().any(|arg| { - has_unused_must_use(&arg.1, statements_analyzer, stmt, context) - }); + return boxed_call + .args + .iter() + .any(|arg| has_unused_must_use(&arg.1, statements_analyzer)); } let codebase = statements_analyzer.get_codebase(); @@ -435,12 +434,12 @@ fn has_unused_must_use( } } aast::Expr_::Await(await_expr) => { - return has_unused_must_use(await_expr, statements_analyzer, stmt, context) + return has_unused_must_use(await_expr, statements_analyzer) } _ => (), } - return false; + false } fn analyze_awaitall( diff --git a/src/code_info/issue.rs b/src/code_info/issue.rs index d0bb0092..8dca9c3b 100644 --- a/src/code_info/issue.rs +++ b/src/code_info/issue.rs @@ -1,4 +1,5 @@ -use std::str::FromStr; +use std::{hash::Hasher, str::FromStr}; +use core::hash::Hash; use hakana_str::StrId; use rustc_hash::FxHashSet; @@ -218,7 +219,7 @@ impl IssueKind { } } -#[derive(Clone, Debug, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, Serialize, Deserialize)] pub struct Issue { pub kind: IssueKind, pub description: String, @@ -235,6 +236,14 @@ impl PartialEq for Issue { } } +impl Hash for Issue { + fn hash(&self, state: &mut H) { + self.kind.hash(state); + self.pos.hash(state); + self.description.hash(state); + } +} + impl Issue { pub fn new( kind: IssueKind,