Skip to content

Commit 890e5f6

Browse files
authored
Fix Rust lint CI (#14602)
1 parent acea4d7 commit 890e5f6

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

.github/workflows/tests.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,29 @@ jobs:
109109
components: clippy
110110
- uses: Swatinem/rust-cache@v2
111111

112-
- run: cargo clippy
112+
- run: cargo clippy -- -D warnings
113+
114+
# We also lint against a nightly rustc so that we can lint the benchmark
115+
# suite, which requires a nightly compiler.
116+
lint-clippy-nightly:
117+
runs-on: ubuntu-latest
118+
needs: changes
119+
if: ${{ needs.changes.outputs.rust == 'true' }}
120+
121+
steps:
122+
- uses: actions/checkout@v3
123+
124+
- name: Install Rust
125+
# There don't seem to be versioned releases of this action per se: for each rust
126+
# version there is a branch which gets constantly rebased on top of master.
127+
# We pin to a specific commit for paranoia's sake.
128+
uses: dtolnay/rust-toolchain@e645b0cf01249a964ec099494d38d2da0f0b349f
129+
with:
130+
toolchain: nightly-2022-12-01
131+
components: clippy
132+
- uses: Swatinem/rust-cache@v2
133+
134+
- run: cargo clippy --all-features -- -D warnings
113135

114136
lint-rustfmt:
115137
runs-on: ubuntu-latest

changelog.d/14602.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix Rust lint CI.

rust/benches/evaluator.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ fn bench_match_exact(b: &mut Bencher) {
3333
let eval = PushRuleEvaluator::py_new(
3434
flattened_keys,
3535
10,
36-
0,
36+
Some(0),
3737
Default::default(),
3838
Default::default(),
3939
true,
40+
vec![],
41+
false,
4042
)
4143
.unwrap();
4244

@@ -67,10 +69,12 @@ fn bench_match_word(b: &mut Bencher) {
6769
let eval = PushRuleEvaluator::py_new(
6870
flattened_keys,
6971
10,
70-
0,
72+
Some(0),
7173
Default::default(),
7274
Default::default(),
7375
true,
76+
vec![],
77+
false,
7478
)
7579
.unwrap();
7680

@@ -101,10 +105,12 @@ fn bench_match_word_miss(b: &mut Bencher) {
101105
let eval = PushRuleEvaluator::py_new(
102106
flattened_keys,
103107
10,
104-
0,
108+
Some(0),
105109
Default::default(),
106110
Default::default(),
107111
true,
112+
vec![],
113+
false,
108114
)
109115
.unwrap();
110116

@@ -135,10 +141,12 @@ fn bench_eval_message(b: &mut Bencher) {
135141
let eval = PushRuleEvaluator::py_new(
136142
flattened_keys,
137143
10,
138-
0,
144+
Some(0),
139145
Default::default(),
140146
Default::default(),
141147
true,
148+
vec![],
149+
false,
142150
)
143151
.unwrap();
144152

rust/src/push/evaluator.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::borrow::Cow;
1615
use std::collections::BTreeMap;
1716

18-
use crate::push::{PushRule, PushRules};
1917
use anyhow::{Context, Error};
2018
use lazy_static::lazy_static;
2119
use log::warn;
@@ -98,6 +96,7 @@ pub struct PushRuleEvaluator {
9896
#[pymethods]
9997
impl PushRuleEvaluator {
10098
/// Create a new `PushRuleEvaluator`. See struct docstring for details.
99+
#[allow(clippy::too_many_arguments)]
101100
#[new]
102101
pub fn py_new(
103102
flattened_keys: BTreeMap<String, String>,
@@ -153,15 +152,12 @@ impl PushRuleEvaluator {
153152
let mut has_rver_condition = false;
154153

155154
for condition in push_rule.conditions.iter() {
156-
has_rver_condition = has_rver_condition
157-
|| match condition {
158-
Condition::Known(known) => match known {
159-
// per MSC3932, we just need *any* room version condition to match
160-
KnownCondition::RoomVersionSupports { feature: _ } => true,
161-
_ => false,
162-
},
163-
_ => false,
164-
};
155+
has_rver_condition |= matches!(
156+
condition,
157+
// per MSC3932, we just need *any* room version condition to match
158+
Condition::Known(KnownCondition::RoomVersionSupports { feature: _ }),
159+
);
160+
165161
match self.match_condition(condition, user_id, display_name) {
166162
Ok(true) => {}
167163
Ok(false) => continue 'outer,
@@ -444,6 +440,10 @@ fn push_rule_evaluator() {
444440

445441
#[test]
446442
fn test_requires_room_version_supports_condition() {
443+
use std::borrow::Cow;
444+
445+
use crate::push::{PushRule, PushRules};
446+
447447
let mut flattened_keys = BTreeMap::new();
448448
flattened_keys.insert("content.body".to_string(), "foo bar bob hello".to_string());
449449
let flags = vec![RoomVersionFeatures::ExtensibleEvents.as_str().to_string()];

0 commit comments

Comments
 (0)