Skip to content

Commit 44ed29b

Browse files
committed
fix: resolve dead_code and clippy warnings exposed by --all-features
- Allow dead_code on intentionally unused methods/fields in rocksdb - Allow clippy::collapsible_if on patterns that would require unstable && let syntax (let_chains, RFC 2497) for MSRV 1.86 compatibility - Collapse bool-inner if-let chains where && with non-let condition - Fix needless_borrows_for_generic_args, redundant_closure, unnecessary_lazy_evaluations, unnecessary_sort_by across backends - Add clippy::too_many_arguments, clippy::type_complexity allows - Scope RwLock guards in mod.rs to avoid await_holding_lock
1 parent b801acb commit 44ed29b

14 files changed

Lines changed: 101 additions & 65 deletions

File tree

crates/aegis-core/src/engine/analysis/graph.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl GraphEngine {
2020
) -> AegisResult<ReachabilityReport> {
2121
// Cache check
2222
let cache_key = format!("reach:{}:{}:{}", resource.as_str(), max_depth, max_nodes);
23+
#[allow(clippy::collapsible_if)]
2324
if let Some(ttl) = cache_ttl_ms {
2425
if let Some(cached) = self.get_cached_analysis(&cache_key, ttl) {
2526
return Ok(cached);
@@ -188,7 +189,7 @@ impl GraphEngine {
188189
})
189190
.collect();
190191

191-
result.sort_by(|a, b| b.resource_count.cmp(&a.resource_count));
192+
result.sort_by_key(|b| std::cmp::Reverse(b.resource_count));
192193
Ok(result)
193194
}
194195

@@ -210,6 +211,7 @@ impl GraphEngine {
210211
}
211212

212213
fn set_cached_analysis(&self, key: &str, value: &impl serde::Serialize, ttl_ms: u64) {
214+
#[allow(clippy::collapsible_if)]
213215
if let Ok(mut cache) = self.analysis_cache.lock() {
214216
if let Ok(json) = serde_json::to_string(value) {
215217
cache.insert(key.to_string(), (Instant::now(), ttl_ms, json));

crates/aegis-core/src/engine/analysis/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl GraphEngine {
4848
if !allowed {
4949
let schema = self.schema.read().unwrap();
5050
let type_def = schema.types.get(&resource_type);
51+
#[allow(clippy::collapsible_if)]
5152
if let Some(type_def) = type_def {
5253
if !type_def.deny.is_empty() {
5354
'deny_check: for deny_def in &type_def.deny {
@@ -56,6 +57,7 @@ impl GraphEngine {
5657
Ok(r) => r,
5758
Err(_) => continue,
5859
};
60+
#[allow(clippy::collapsible_if)]
5961
if let Ok(tr) = crate::engine::traversal::bfs_traversal(
6062
&self.active_partition_id(),
6163
self.storage.as_ref(),

crates/aegis-core/src/engine/cache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl DecisionCache {
108108
self.access_order.retain(|k| k != &key);
109109

110110
// Evict LRU entry if at capacity
111+
#[allow(clippy::collapsible_if)]
111112
if self.entries.len() >= self.capacity {
112113
if let Some(lru_key) = self.access_order.pop_front() {
113114
self.entries.remove(&lru_key);
@@ -228,6 +229,7 @@ impl TraversalCache {
228229
self.access_order.retain(|k| k != &key);
229230

230231
// Evict LRU entry if at capacity
232+
#[allow(clippy::collapsible_if)]
231233
if self.entries.len() >= self.capacity {
232234
if let Some(lru_key) = self.access_order.pop_front() {
233235
self.entries.remove(&lru_key);

crates/aegis-core/src/engine/enforcement_history.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl GraphEngine {
158158
*resource_counts.entry(e.resource.clone()).or_default() += 1;
159159
}
160160
let mut by_resource: Vec<(String, u64)> = resource_counts.into_iter().collect();
161-
by_resource.sort_by(|a, b| b.1.cmp(&a.1));
161+
by_resource.sort_by_key(|b| std::cmp::Reverse(b.1));
162162

163163
Ok(EnforcementTrends {
164164
total_events,
@@ -240,6 +240,8 @@ impl GraphEngine {
240240
}
241241

242242
// Periodically purge expired events (every ~1000 records)
243+
// Periodically purge expired events (every ~1000 records)
244+
#[allow(clippy::collapsible_if)]
243245
if cfg.max_days > 0 {
244246
if let Ok(mut events) = self.enforcement_events.lock() {
245247
if events.len() % 1000 == 0 {

crates/aegis-core/src/engine/mod.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ impl GraphEngine {
265265

266266
/// Emit a structured log event through the registered callback (if any).
267267
fn emit_log(&self, level: hooks::LogLevel, message: &str, context: &str) {
268+
#[allow(clippy::collapsible_if)]
268269
if let Ok(guard) = self.logger.lock() {
269270
if let Some(ref logger) = *guard {
270271
logger(level, message, context);
@@ -458,6 +459,7 @@ impl GraphEngine {
458459
#[cfg(feature = "hot-reload")]
459460
pub fn stop_watcher(&self) {
460461
self.shutdown_flag.store(true, Ordering::Relaxed);
462+
#[allow(clippy::collapsible_if)]
461463
if let Ok(mut guard) = self.watcher_thread.lock() {
462464
if let Some(handle) = guard.take() {
463465
handle.join().ok();
@@ -739,6 +741,7 @@ impl GraphEngine {
739741
Some(ctx_ref.as_ref()),
740742
None,
741743
);
744+
#[allow(clippy::collapsible_if)]
742745
if let Ok(r) = result {
743746
if r.found && evaluate_condition_if_present(cond.as_ref(), ctx_ref.as_ref())
744747
{
@@ -907,19 +910,21 @@ impl GraphEngine {
907910

908911
// Resolve permission to relations
909912
let resource_type = resource_type_name(resource.as_str());
910-
let schema = self.schema.read().unwrap();
911-
let resolved = match policy::resolve_permission(&schema, &resource_type, permission) {
912-
Some(r) => r,
913-
None => {
914-
crate::telemetry::inc_check_total();
915-
crate::telemetry::inc_check_denied();
916-
return Ok(CheckResult {
917-
allowed: false,
918-
revision,
919-
});
920-
}
913+
let resolved = {
914+
let schema = self.schema.read().unwrap();
915+
let result = match policy::resolve_permission(&schema, &resource_type, permission) {
916+
Some(r) => r,
917+
None => {
918+
crate::telemetry::inc_check_total();
919+
crate::telemetry::inc_check_denied();
920+
return Ok(CheckResult {
921+
allowed: false,
922+
revision,
923+
});
924+
}
925+
};
926+
result
921927
};
922-
drop(schema);
923928

924929
// Evaluate each candidate relation by checking tuples from async storage
925930
let mut allowed = false;
@@ -1140,6 +1145,7 @@ impl GraphEngine {
11401145
Some(revision),
11411146
consistency,
11421147
);
1148+
#[allow(clippy::collapsible_if)]
11431149
if let Ok(tr) = traversal_result {
11441150
if tr.found {
11451151
allowed = false;
@@ -1293,6 +1299,7 @@ impl GraphEngine {
12931299
Some(revision),
12941300
consistency,
12951301
);
1302+
#[allow(clippy::collapsible_if)]
12961303
if let Ok(tr) = tr {
12971304
if tr.found {
12981305
allowed = false;
@@ -1458,18 +1465,19 @@ impl GraphEngine {
14581465
.check(&rl_key, RateLimitOp::Write)?;
14591466

14601467
let resource_type = resource_type_name(tuple.object.as_str());
1461-
let schema = self.schema.read().unwrap();
1462-
let type_def = match schema.types.get(&resource_type) {
1463-
Some(t) => t,
1464-
None => return Err(AegisError::UnknownSubjectType(resource_type)),
1465-
};
1466-
if !type_def.relations.contains_key(tuple.relation.as_str()) {
1467-
return Err(AegisError::UnknownRelation {
1468-
type_name: resource_type,
1469-
relation: tuple.relation.to_string(),
1470-
});
1468+
{
1469+
let schema = self.schema.read().unwrap();
1470+
let type_def = match schema.types.get(&resource_type) {
1471+
Some(t) => t,
1472+
None => return Err(AegisError::UnknownSubjectType(resource_type)),
1473+
};
1474+
if !type_def.relations.contains_key(tuple.relation.as_str()) {
1475+
return Err(AegisError::UnknownRelation {
1476+
type_name: resource_type,
1477+
relation: tuple.relation.to_string(),
1478+
});
1479+
}
14711480
}
1472-
drop(schema);
14731481

14741482
let storage = self
14751483
.async_storage
@@ -2062,6 +2070,7 @@ impl GraphEngine {
20622070
let Some(threshold) = self.wal_checkpoint_threshold else {
20632071
return;
20642072
};
2073+
#[allow(clippy::collapsible_if)]
20652074
if let Some(wal_size) = self.storage.wal_size_mb() {
20662075
if wal_size > threshold {
20672076
let _ = self.storage.close();

crates/aegis-core/src/engine/partition.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl PartitionManager {
5353

5454
pub fn check_rate_limit(&self, partition_id: &PartitionId) -> AegisResult<()> {
5555
let key = partition_id.to_string();
56+
#[allow(clippy::collapsible_if)]
5657
if let Ok(map) = self.partitions.lock() {
5758
if let Some(state) = map.get(&key) {
5859
return state.rate_limiter.check(&key, RateLimitOp::Check);

crates/aegis-core/src/engine/ratelimit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl TokenBucketRateLimiter {
7575

7676
// Evict the least-recently-accessed entry if we need to insert a new key
7777
// and the map is at capacity.
78+
#[allow(clippy::collapsible_if)]
7879
if !buckets.contains_key(key) && buckets.len() >= self.config.max_keys {
7980
if let Some(oldest_key) = buckets
8081
.iter()

crates/aegis-core/src/engine/traversal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ pub fn bfs_traversal_with_limits_and_context(
264264
// Subject-set resolution: if the tuple's subject is a subject-set
265265
// (e.g. "team:eng#member"), we need to verify that our original
266266
// traversal subject satisfies the subject-set condition.
267+
#[allow(clippy::collapsible_if)]
267268
if let Some(ref subject_set) = tuple.subject.as_subject_set() {
268269
if !is_subject_set_member(
269270
partition_id,
@@ -399,6 +400,7 @@ fn check_direct(
399400
return Ok(true);
400401
}
401402
// Subject-set match: subject is like `team:eng#member`
403+
#[allow(clippy::collapsible_if)]
402404
if let Some(ref subject_set) = t.subject.as_subject_set() {
403405
if is_subject_set_member(
404406
partition_id,

crates/aegis-core/src/engine/watch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,25 @@ pub struct WatchFilter {
4646

4747
impl WatchFilter {
4848
pub fn matches(&self, event: &WatchEvent) -> bool {
49+
#[allow(clippy::collapsible_if)]
4950
if let Some(subjects) = &self.subjects {
5051
if !subjects.iter().any(|s| s == &event.subject) {
5152
return false;
5253
}
5354
}
55+
#[allow(clippy::collapsible_if)]
5456
if let Some(relations) = &self.relations {
5557
if !relations.iter().any(|r| r == &event.relation) {
5658
return false;
5759
}
5860
}
61+
#[allow(clippy::collapsible_if)]
5962
if let Some(objects) = &self.objects {
6063
if !objects.iter().any(|o| o == &event.object) {
6164
return false;
6265
}
6366
}
67+
#[allow(clippy::collapsible_if)]
6468
if let Some(types) = &self.event_types {
6569
if !types.contains(&event.event_type) {
6670
return false;

crates/aegis-core/src/schema/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ pub fn lint_schema(schema: &Schema) -> LintResult {
209209

210210
// Check condition syntax on permissions
211211
for (perm_name, perm_def) in &type_def.permissions {
212+
#[allow(clippy::collapsible_if)]
212213
if let Some(ref cond) = perm_def.condition {
213214
if let Err(e) = crate::engine::condition::parse_condition(cond) {
214215
diagnostics.push(LintDiagnostic {

0 commit comments

Comments
 (0)