Skip to content

Commit aeab658

Browse files
committed
fix: clippy warnings
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent f27f695 commit aeab658

8 files changed

Lines changed: 32 additions & 50 deletions

File tree

examples/helpers/type_analysis.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub fn rego_type_analysis(
377377
let head_display = spec
378378
.head_fact
379379
.as_ref()
380-
.map(|fact| format_fact_summary(fact))
380+
.map(format_fact_summary)
381381
.unwrap_or_else(|| "Unknown".to_owned());
382382
println!(" - {} → {}", signature_display, head_display);
383383

@@ -482,7 +482,7 @@ pub fn rego_type_analysis(
482482
let head_display = spec
483483
.head_fact
484484
.as_ref()
485-
.map(|fact| format_fact_summary(fact))
485+
.map(format_fact_summary)
486486
.unwrap_or_else(|| "Unknown".to_owned());
487487
println!(
488488
" • {} → {}",
@@ -544,7 +544,7 @@ fn format_specialization_signature(rule_path: &str, spec: &RuleSpecializationRec
544544
let args: Vec<String> = spec
545545
.parameter_facts
546546
.iter()
547-
.map(|fact| format_fact_summary(fact))
547+
.map(format_fact_summary)
548548
.collect();
549549

550550
let joined = if args.is_empty() {
@@ -674,10 +674,7 @@ fn describe_structural_type_impl(st: &StructuralType) -> String {
674674
}
675675
}
676676
StructuralType::Union(types) => {
677-
let rendered: Vec<String> = types
678-
.iter()
679-
.map(|ty| describe_structural_type_impl(ty))
680-
.collect();
677+
let rendered: Vec<String> = types.iter().map(describe_structural_type_impl).collect();
681678
format!("Union[{}]", rendered.join(", "))
682679
}
683680
StructuralType::Enum(values) => {

src/engine.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ impl Default for Engine {
6363
}
6464
}
6565

66+
/// Bundled artifacts used by the type analyzer when operating on an engine.
67+
pub(crate) type TypeAnalysisContext = (
68+
Rc<Vec<Ref<Module>>>,
69+
Option<Rc<crate::scheduler::Schedule>>,
70+
Option<Rc<crate::compiler::hoist::HoistedLoopsLookup>>,
71+
Rc<CompiledPolicyData>,
72+
);
73+
6674
impl Engine {
6775
/// Create an instance of [Engine].
6876
pub fn new() -> Self {
@@ -1613,14 +1621,7 @@ impl Engine {
16131621
/// Get the context needed for type analysis.
16141622
/// Returns (modules, schedule, loop_lookup, compiled_policy) for use by TypeAnalyzer.
16151623
/// The engine will prepare itself if needed. Returns None if preparation fails.
1616-
pub(crate) fn get_type_analysis_context(
1617-
&mut self,
1618-
) -> Option<(
1619-
Rc<Vec<Ref<Module>>>,
1620-
Option<Rc<crate::scheduler::Schedule>>,
1621-
Option<Rc<crate::compiler::hoist::HoistedLoopsLookup>>,
1622-
Rc<CompiledPolicyData>,
1623-
)> {
1624+
pub(crate) fn get_type_analysis_context(&mut self) -> Option<TypeAnalysisContext> {
16241625
if self.prepare_for_eval(false, false).is_err() {
16251626
return None;
16261627
}
@@ -1641,7 +1642,7 @@ impl Engine {
16411642
rule_path: &str,
16421643
) -> Option<crate::value::Value> {
16431644
// Prepare the engine if not already prepared
1644-
if let Err(_) = self.prepare_for_eval(false, false) {
1645+
if self.prepare_for_eval(false, false).is_err() {
16451646
return None;
16461647
}
16471648

src/type_analysis/propagation/expressions/rules/calls/effects.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ pub(crate) fn apply_rule_call_effects(
7373
);
7474

7575
if !scratch_result.diagnostics.is_empty() {
76-
result
77-
.diagnostics
78-
.extend(scratch_result.diagnostics.drain(..));
76+
result.diagnostics.append(&mut scratch_result.diagnostics);
7977
}
8078

8179
let head_fact = scratch_result

src/type_analysis/propagation/pipeline/analyzer/rule_analysis/bodies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use super::super::super::result::AnalysisState;
1414
use super::super::TypeAnalyzer;
1515

1616
impl TypeAnalyzer {
17+
#[allow(clippy::too_many_arguments)]
1718
pub(super) fn analyze_rule_body(
1819
&self,
1920
module_idx: u32,

src/type_analysis/propagation/pipeline/analyzer/rule_analysis/heads.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ impl TypeAnalyzer {
175175
}
176176
Self::merge_rule_head_origins(&mut existing.origins, origins);
177177
if !specialization_hits.is_empty() {
178-
existing
179-
.specialization_hits
180-
.extend(specialization_hits.into_iter());
178+
existing.specialization_hits.extend(specialization_hits);
181179
}
182180
} else {
183181
let mut stored = TypeFact::new(descriptor, provenance);

src/type_analysis/propagation/pipeline/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl AnalysisState {
7878
let signature = record.signature.clone();
7979
self.function_rule_specializations
8080
.entry(key)
81-
.or_insert_with(BTreeMap::new)
81+
.or_default()
8282
.insert(signature, record);
8383
}
8484

src/type_analysis/result/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ pub struct TypeAnalysisResult {
4141
}
4242

4343
fn rule_returns_boolean_by_default(head: &RuleHead) -> bool {
44-
match head {
45-
RuleHead::Func { assign: None, .. } => true,
46-
RuleHead::Compr { assign: None, .. } => true,
47-
RuleHead::Set { .. } => true,
48-
_ => false,
49-
}
44+
matches!(
45+
head,
46+
RuleHead::Func { assign: None, .. }
47+
| RuleHead::Compr { assign: None, .. }
48+
| RuleHead::Set { .. }
49+
)
5050
}
5151

5252
fn default_true_body_fact() -> TypeFact {
@@ -193,17 +193,14 @@ impl TypeAnalysisResult {
193193
col: span.col,
194194
};
195195

196-
let value_expr_idx = body
197-
.assign
198-
.as_ref()
199-
.map(|assign| assign.value.eidx())
200-
.or_else(|| {
196+
let value_expr_idx =
197+
body.assign.as_ref().map(|assign| assign.value.eidx()).or(
201198
if body_idx == 0 {
202199
head_value_expr_idx
203200
} else {
204201
None
205-
}
206-
});
202+
},
203+
);
207204

208205
let mut value_fact = value_expr_idx
209206
.and_then(|idx| state.lookup.get_expr(module_idx_u32, idx))

src/type_analysis/result/rules.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,23 @@ pub struct RuleBodySummary {
9494
}
9595

9696
/// Distinguishes the main body from `else` bodies within a definition.
97-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
97+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
9898
pub enum RuleBodyKind {
99+
#[default]
99100
Primary,
100101
Else,
101102
}
102103

103-
impl Default for RuleBodyKind {
104-
fn default() -> Self {
105-
RuleBodyKind::Primary
106-
}
107-
}
108-
109104
/// Classification for rule heads.
110-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
105+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
111106
pub enum RuleKind {
107+
#[default]
112108
Complete,
113109
PartialSet,
114110
PartialObject,
115111
Function,
116112
}
117113

118-
impl Default for RuleKind {
119-
fn default() -> Self {
120-
RuleKind::Complete
121-
}
122-
}
123-
124114
/// Specialization record captured for function rules.
125115
#[derive(Clone, Debug)]
126116
pub struct RuleSpecializationRecord {

0 commit comments

Comments
 (0)