Skip to content

Commit

Permalink
Fix clippy complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 11, 2024
1 parent 474f572 commit ca20c5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
13 changes: 5 additions & 8 deletions src/analyzer/stmt/if_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FxHashSet<_>>());
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::<FxHashSet<_>>();

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
Expand Down
15 changes: 7 additions & 8 deletions src/analyzer/stmt_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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();
Expand All @@ -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(
Expand Down
13 changes: 11 additions & 2 deletions src/code_info/issue.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -235,6 +236,14 @@ impl PartialEq for Issue {
}
}

impl Hash for Issue {
fn hash<H: Hasher>(&self, state: &mut H) {
self.kind.hash(state);
self.pos.hash(state);
self.description.hash(state);
}
}

impl Issue {
pub fn new(
kind: IssueKind,
Expand Down

0 comments on commit ca20c5a

Please sign in to comment.