diff --git a/crates/ruff_linter/src/registry/rule_set.rs b/crates/ruff_linter/src/registry/rule_set.rs index 6c15feba9a57f..450502d41c502 100644 --- a/crates/ruff_linter/src/registry/rule_set.rs +++ b/crates/ruff_linter/src/registry/rule_set.rs @@ -234,6 +234,7 @@ impl RuleSet { /// assert!(set.contains(Rule::AmbiguousFunctionName)); /// assert!(!set.contains(Rule::BreakOutsideLoop)); /// ``` + #[inline] pub const fn contains(&self, rule: Rule) -> bool { let rule = rule as u16; let index = rule as usize / Self::SLICE_BITS as usize; @@ -243,6 +244,20 @@ impl RuleSet { self.0[index] & mask != 0 } + /// Returns `true` if any of the rules in `rules` are in this set. + #[inline] + pub const fn any(&self, rules: &[Rule]) -> bool { + let mut any = false; + let mut i = 0; + + while i < rules.len() { + any |= self.contains(rules[i]); + i += 1; + } + + any + } + /// Returns an iterator over the rules in this set. /// /// ## Examples diff --git a/crates/ruff_linter/src/settings/rule_table.rs b/crates/ruff_linter/src/settings/rule_table.rs index 2e598cbf44d36..9f7a6e2ec151c 100644 --- a/crates/ruff_linter/src/settings/rule_table.rs +++ b/crates/ruff_linter/src/settings/rule_table.rs @@ -31,7 +31,7 @@ impl RuleTable { /// Returns whether any of the given rules should be checked. #[inline] pub const fn any_enabled(&self, rules: &[Rule]) -> bool { - self.enabled.intersects(&RuleSet::from_rules(rules)) + self.enabled.any(rules) } /// Returns whether violations of the given rule should be fixed.