Skip to content

Commit 7acd824

Browse files
committed
chore: apply all clippy pedantic fixes
Signed-off-by: azjezz <[email protected]>
1 parent 0321ead commit 7acd824

File tree

635 files changed

+6377
-2309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

635 files changed

+6377
-2309
lines changed

crates/algebra/src/assertion_set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub fn add_and_clause(assertion_set: &mut AssertionSet, or_assertions: &[Asserti
7878
/// This function applies De Morgan's laws to the formula. The process involves:
7979
/// 1. Converting the CNF formula `(A OR B) AND C` to its negated DNF form: `(NOT A AND NOT B) OR (NOT C)`.
8080
/// 2. Converting the resulting DNF back to CNF using the distributive property.
81+
#[must_use]
8182
pub fn negate_assertion_set(assertion_set: AssertionSet) -> AssertionSet {
8283
// 1. Apply De Morgan's laws to get the DNF representation.
8384
// `(A OR B) AND C` becomes `(¬A AND ¬B) OR (¬C)`.

crates/algebra/src/clause.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl Hash for Clause {
3838
}
3939

4040
impl Clause {
41+
#[must_use]
4142
pub fn new(
4243
possibilities: IndexMap<Atom, IndexMap<u64, Assertion>>,
4344
condition_span: Span,
@@ -57,6 +58,7 @@ impl Clause {
5758
}
5859
}
5960

61+
#[must_use]
6062
pub fn remove_possibilities(&self, var_id: &Atom) -> Option<Clause> {
6163
let mut possibilities = self.possibilities.clone();
6264

@@ -76,6 +78,7 @@ impl Clause {
7678
))
7779
}
7880

81+
#[must_use]
7982
pub fn add_possibility(&self, var_id: Atom, new_possibility: IndexMap<u64, Assertion>) -> Clause {
8083
let mut possibilities = self.possibilities.clone();
8184

@@ -91,6 +94,7 @@ impl Clause {
9194
)
9295
}
9396

97+
#[must_use]
9498
pub fn contains(&self, other_clause: &Self) -> bool {
9599
if other_clause.possibilities.len() > self.possibilities.len() {
96100
return false;
@@ -103,6 +107,7 @@ impl Clause {
103107
})
104108
}
105109

110+
#[must_use]
106111
pub fn get_impossibilities(&self) -> BTreeMap<Atom, Vec<Assertion>> {
107112
self.possibilities
108113
.iter()
@@ -114,6 +119,7 @@ impl Clause {
114119
.collect()
115120
}
116121

122+
#[must_use]
117123
pub fn to_atom(&self) -> Atom {
118124
if self.possibilities.is_empty() {
119125
return atom("<empty>");
@@ -176,7 +182,7 @@ fn get_hash(
176182
if wedge || !reconcilable {
177183
(Wrapping(clause_span.start.offset)
178184
+ Wrapping(clause_span.end.offset)
179-
+ Wrapping(if wedge { 100000 } else { 0 }))
185+
+ Wrapping(if wedge { 100_000 } else { 0 }))
180186
.0
181187
} else {
182188
let mut hasher = AHasher::default();

crates/algebra/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ pub fn find_satisfying_assignments(
381381
///
382382
/// A `Vec<Clause>` representing the resulting CNF formula.
383383
#[inline]
384+
#[must_use]
384385
pub fn disjoin_clauses(
385386
left_clauses: Vec<Clause>,
386387
right_clauses: Vec<Clause>,
@@ -504,6 +505,7 @@ pub fn disjoin_clauses(
504505
/// A `Some(Vec<Clause>)` representing the negated and simplified CNF formula,
505506
/// or `None` if the negation is not possible due to complexity or other constraints.
506507
#[inline]
508+
#[must_use]
507509
pub fn negate_formula(mut clauses: Vec<Clause>) -> Option<Vec<Clause>> {
508510
clauses.retain(|clause| clause.reconcilable);
509511

crates/analyzer/src/analysis_result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct AnalysisResult {
1212
}
1313

1414
impl AnalysisResult {
15+
#[must_use]
1516
pub fn new(symbol_references: SymbolReferences) -> Self {
1617
Self {
1718
issues: IssueCollection::default(),

crates/analyzer/src/assertion.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ use mago_codex::ttype::get_array_value_parameter;
1717
use mago_codex::ttype::get_iterable_value_parameter;
1818
use mago_span::HasSpan;
1919
use mago_span::Span;
20-
use mago_syntax::ast::*;
20+
use mago_syntax::ast::Access;
21+
use mago_syntax::ast::BinaryOperator;
22+
use mago_syntax::ast::Call;
23+
use mago_syntax::ast::ClassConstantAccess;
24+
use mago_syntax::ast::ClassLikeConstantSelector;
25+
use mago_syntax::ast::Construct;
26+
use mago_syntax::ast::Expression;
27+
use mago_syntax::ast::FunctionCall;
28+
use mago_syntax::ast::Literal;
29+
use mago_syntax::ast::LocalIdentifier;
30+
use mago_syntax::ast::UnaryPrefix;
31+
use mago_syntax::ast::UnaryPrefixOperator;
2132

2233
use crate::artifacts::AnalysisArtifacts;
2334
use crate::context::assertion::AssertionContext;
@@ -115,7 +126,7 @@ pub fn scrape_assertions(
115126
}
116127
}
117128
Construct::Isset(isset_construct) => {
118-
for value in isset_construct.values.iter() {
129+
for value in &isset_construct.values {
119130
if let Some(value_id) = get_expression_id(
120131
value,
121132
assertion_context.this_class_name,

crates/analyzer/src/code.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub enum IssueCode {
291291
}
292292

293293
impl IssueCode {
294+
#[must_use]
294295
pub fn as_str(&self) -> &'static str {
295296
match self {
296297
Self::AbstractClassUsedAsAttribute => "abstract-class-used-as-attribute",
@@ -583,6 +584,7 @@ impl IssueCode {
583584
}
584585
}
585586

587+
#[must_use]
586588
pub fn as_u16(&self) -> u16 {
587589
*self as u16
588590
}

crates/analyzer/src/common/construct.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use mago_reporting::Annotation;
99
use mago_reporting::Issue;
1010
use mago_span::HasSpan;
1111
use mago_span::Span;
12-
use mago_syntax::ast::*;
12+
use mago_syntax::ast::ArgumentList;
13+
use mago_syntax::ast::Expression;
1314

1415
use crate::analyzable::Analyzable;
1516
use crate::artifacts::AnalysisArtifacts;
@@ -38,7 +39,7 @@ pub fn analyze_construct_inputs<'ctx, 'arena>(
3839
construct_kind: &'static str,
3940
construct_keyword: Span,
4041
inputs: ConstructInput<'_, 'arena>,
41-
expected_type: TUnion,
42+
expected_type: &TUnion,
4243
is_variadic: bool,
4344
has_default: bool,
4445
has_side_effects: bool,
@@ -83,7 +84,7 @@ pub fn analyze_construct_inputs<'ctx, 'arena>(
8384
verify_construct_input_type(
8485
context,
8586
&input_type,
86-
&expected_type,
87+
expected_type,
8788
index,
8889
argument.value(),
8990
construct_kind,
@@ -101,7 +102,7 @@ pub fn analyze_construct_inputs<'ctx, 'arena>(
101102
verify_construct_input_type(
102103
context,
103104
&input_type,
104-
&expected_type,
105+
expected_type,
105106
0,
106107
expression,
107108
construct_kind,
@@ -139,7 +140,7 @@ pub fn analyze_construct_inputs<'ctx, 'arena>(
139140
verify_construct_input_type(
140141
context,
141142
&input_type,
142-
&expected_type,
143+
expected_type,
143144
index,
144145
expression,
145146
construct_kind,

crates/analyzer/src/common/global.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ use mago_codex::ttype::atomic::array::list::TList;
1212
use mago_codex::ttype::atomic::scalar::TScalar;
1313
use mago_codex::ttype::atomic::scalar::int::TInteger;
1414
use mago_codex::ttype::atomic::scalar::string::TString;
15+
use mago_codex::ttype::get_bool;
16+
use mago_codex::ttype::get_float;
17+
use mago_codex::ttype::get_int_range;
18+
use mago_codex::ttype::get_mixed;
19+
use mago_codex::ttype::get_non_empty_string;
20+
use mago_codex::ttype::get_non_negative_int;
21+
use mago_codex::ttype::get_one_int;
22+
use mago_codex::ttype::get_positive_int;
23+
use mago_codex::ttype::get_string;
24+
use mago_codex::ttype::get_truthy_string;
1525
use mago_codex::ttype::union::TUnion;
16-
use mago_codex::ttype::*;
1726

1827
std::thread_local! {
1928
static SUPERGLOBALS_MAP: LazyLock<HashMap<&'static str, Rc<TUnion>>> = LazyLock::new(|| {
@@ -98,7 +107,7 @@ std::thread_local! {
98107
// This value (1764191486) was chosen at the time of implementation and has no special meaning.
99108
// Using a dynamic timestamp would cause baseline matching to fail since error messages
100109
// include the type, and the type would change on every run.
101-
const REQUEST_TIME_MIN: i64 = 1764191486;
110+
const REQUEST_TIME_MIN: i64 = 1_764_191_486;
102111

103112
let mut known_items = BTreeMap::new();
104113
// Standard CGI/1.1 and PHP variables

crates/analyzer/src/common/synthetic.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ use bumpalo::vec;
33

44
use mago_span::HasSpan;
55
use mago_span::Span;
6+
use mago_syntax::ast::Argument;
7+
use mago_syntax::ast::ArgumentList;
8+
use mago_syntax::ast::Binary;
9+
use mago_syntax::ast::BinaryOperator;
10+
use mago_syntax::ast::Call;
11+
use mago_syntax::ast::DirectVariable;
12+
use mago_syntax::ast::Expression;
13+
use mago_syntax::ast::FunctionCall;
14+
use mago_syntax::ast::Literal;
15+
use mago_syntax::ast::LiteralString;
16+
use mago_syntax::ast::LiteralStringKind;
17+
use mago_syntax::ast::PositionalArgument;
18+
use mago_syntax::ast::UnaryPrefix;
19+
use mago_syntax::ast::UnaryPrefixOperator;
20+
use mago_syntax::ast::Variable;
621
use mago_syntax::ast::sequence::TokenSeparatedSequence;
7-
use mago_syntax::ast::*;
822

923
pub fn new_synthetic_call<'arena>(arena: &'arena Bump, f: &str, expression: Expression<'arena>) -> Expression<'arena> {
1024
Expression::Call(Call::Function(FunctionCall {

crates/analyzer/src/context/block.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'ctx> BlockContext<'ctx> {
315315

316316
for key in c.possibilities.keys() {
317317
for changed_var_id in changed_var_ids {
318-
if changed_var_id == key || var_has_root(key, changed_var_id) {
318+
if changed_var_id == key || var_has_root(*key, *changed_var_id) {
319319
rejected_clauses.push(c.clone());
320320
continue 'outer;
321321
}
@@ -353,7 +353,7 @@ impl<'ctx> BlockContext<'ctx> {
353353

354354
pub(crate) fn filter_clauses<'arena>(
355355
context: &mut Context<'ctx, 'arena>,
356-
remove_var_id: &Atom,
356+
remove_var_id: Atom,
357357
clauses: Vec<Rc<Clause>>,
358358
new_type: Option<&TUnion>,
359359
) -> Vec<Rc<Clause>> {
@@ -362,7 +362,7 @@ impl<'ctx> BlockContext<'ctx> {
362362

363363
'outer: for clause in clauses {
364364
for var_id in clause.possibilities.keys() {
365-
if var_has_root(var_id, remove_var_id) {
365+
if var_has_root(*var_id, remove_var_id) {
366366
continue 'outer;
367367
}
368368
}
@@ -381,7 +381,7 @@ impl<'ctx> BlockContext<'ctx> {
381381
{
382382
for clause in other_clauses {
383383
let mut type_changed = false;
384-
let Some(possibilities) = clause.possibilities.get(remove_var_id) else {
384+
let Some(possibilities) = clause.possibilities.get(&remove_var_id) else {
385385
clauses_to_keep.push(clause.clone());
386386

387387
continue;
@@ -422,18 +422,18 @@ impl<'ctx> BlockContext<'ctx> {
422422
pub(crate) fn remove_variable_from_conflicting_clauses<'arena>(
423423
&mut self,
424424
context: &mut Context<'ctx, 'arena>,
425-
remove_var_id: &Atom,
425+
remove_var_id: Atom,
426426
new_type: Option<&TUnion>,
427427
) {
428428
self.clauses = BlockContext::filter_clauses(context, remove_var_id, self.clauses.clone(), new_type);
429429

430-
self.parent_conflicting_clause_variables.insert(*remove_var_id);
430+
self.parent_conflicting_clause_variables.insert(remove_var_id);
431431
}
432432

433433
pub(crate) fn remove_descendants<'arena>(
434434
&mut self,
435435
context: &mut Context<'ctx, 'arena>,
436-
remove_var_id: &Atom,
436+
remove_var_id: Atom,
437437
existing_type: &TUnion,
438438
new_type: Option<&TUnion>,
439439
) {
@@ -452,7 +452,7 @@ impl<'ctx> BlockContext<'ctx> {
452452
let keys = self.locals.keys().copied().collect::<Vec<_>>();
453453

454454
for var_id in keys {
455-
if var_has_root(&var_id, remove_var_id) {
455+
if var_has_root(var_id, remove_var_id) {
456456
self.locals.remove(&var_id);
457457
}
458458
}
@@ -505,7 +505,7 @@ impl<'ctx> BlockContext<'ctx> {
505505
if let Some(existing_type) = self.locals.remove(&var_atom)
506506
&& remove_descendants
507507
{
508-
self.remove_descendants(context, &var_atom, &existing_type, None);
508+
self.remove_descendants(context, var_atom, &existing_type, None);
509509
}
510510

511511
self.assigned_variable_ids.remove(&var_atom);
@@ -565,7 +565,7 @@ impl<'ctx> BlockContext<'ctx> {
565565
start_block_context: &Self,
566566
end_block_context: &mut Self,
567567
has_leaving_statements: bool,
568-
vars_to_update: AtomSet,
568+
vars_to_update: &AtomSet,
569569
updated_vars: &mut AtomSet,
570570
) {
571571
for (variable_id, old_type) in &start_block_context.locals {
@@ -709,8 +709,8 @@ pub fn subtract_union_types(context: &mut Context<'_, '_>, existing_type: TUnion
709709
result
710710
}
711711

712-
fn should_keep_clause(clause: &Rc<Clause>, remove_var_id: &Atom, new_type: Option<&TUnion>) -> bool {
713-
if let Some(possibilities) = clause.possibilities.get(remove_var_id) {
712+
fn should_keep_clause(clause: &Rc<Clause>, remove_var_id: Atom, new_type: Option<&TUnion>) -> bool {
713+
if let Some(possibilities) = clause.possibilities.get(&remove_var_id) {
714714
if possibilities.len() == 1
715715
&& let Some((_, Assertion::IsType(assertion_type))) = possibilities.first()
716716
&& let Some(new_type) = new_type

0 commit comments

Comments
 (0)