From 7e482a5960b84fc5bda2ab81862e11dc84326fec Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:36:55 +0000 Subject: [PATCH 1/7] Fix Rust lint CI We weren't correctly reporting warnings as errors. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b687eb002d88..e557095539b6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,7 +109,7 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 - - run: cargo clippy + - run: cargo clippy --all-targets -- -D warnings lint-rustfmt: runs-on: ubuntu-latest From 60984ef9c1ebafe96a2802f280c655c88bfcac71 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:37:57 +0000 Subject: [PATCH 2/7] Newsfile --- changelog.d/14602.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14602.misc diff --git a/changelog.d/14602.misc b/changelog.d/14602.misc new file mode 100644 index 000000000000..9bc294dfc587 --- /dev/null +++ b/changelog.d/14602.misc @@ -0,0 +1 @@ +Fix Rust ling CI. From cdcaaf3eb5631beff817ff9a68e9fc5a49d37718 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:40:21 +0000 Subject: [PATCH 3/7] Fix basic linting errors --- rust/benches/evaluator.rs | 16 ++++++++++++---- rust/src/push/evaluator.rs | 6 ++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/rust/benches/evaluator.rs b/rust/benches/evaluator.rs index ed411461d139..442a79348fcf 100644 --- a/rust/benches/evaluator.rs +++ b/rust/benches/evaluator.rs @@ -33,10 +33,12 @@ fn bench_match_exact(b: &mut Bencher) { let eval = PushRuleEvaluator::py_new( flattened_keys, 10, - 0, + Some(0), Default::default(), Default::default(), true, + vec![], + false, ) .unwrap(); @@ -67,10 +69,12 @@ fn bench_match_word(b: &mut Bencher) { let eval = PushRuleEvaluator::py_new( flattened_keys, 10, - 0, + Some(0), Default::default(), Default::default(), true, + vec![], + false, ) .unwrap(); @@ -101,10 +105,12 @@ fn bench_match_word_miss(b: &mut Bencher) { let eval = PushRuleEvaluator::py_new( flattened_keys, 10, - 0, + Some(0), Default::default(), Default::default(), true, + vec![], + false, ) .unwrap(); @@ -135,10 +141,12 @@ fn bench_eval_message(b: &mut Bencher) { let eval = PushRuleEvaluator::py_new( flattened_keys, 10, - 0, + Some(0), Default::default(), Default::default(), true, + vec![], + false, ) .unwrap(); diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index 1cd54f7e2c31..797931902894 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::borrow::Cow; use std::collections::BTreeMap; -use crate::push::{PushRule, PushRules}; use anyhow::{Context, Error}; use lazy_static::lazy_static; use log::warn; @@ -444,6 +442,10 @@ fn push_rule_evaluator() { #[test] fn test_requires_room_version_supports_condition() { + use std::borrow::Cow; + + use crate::push::{PushRule, PushRules}; + let mut flattened_keys = BTreeMap::new(); flattened_keys.insert("content.body".to_string(), "foo bar bob hello".to_string()); let flags = vec![RoomVersionFeatures::ExtensibleEvents.as_str().to_string()]; From b49d4924287891842b9e8aeccea5cf395936b277 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:44:08 +0000 Subject: [PATCH 4/7] Fix clippy --- rust/src/push/evaluator.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index 797931902894..fadb6690ee15 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -96,6 +96,7 @@ pub struct PushRuleEvaluator { #[pymethods] impl PushRuleEvaluator { /// Create a new `PushRuleEvaluator`. See struct docstring for details. + #[allow(clippy::too_many_arguments)] #[new] pub fn py_new( flattened_keys: BTreeMap, @@ -151,15 +152,12 @@ impl PushRuleEvaluator { let mut has_rver_condition = false; for condition in push_rule.conditions.iter() { - has_rver_condition = has_rver_condition - || match condition { - Condition::Known(known) => match known { - // per MSC3932, we just need *any* room version condition to match - KnownCondition::RoomVersionSupports { feature: _ } => true, - _ => false, - }, - _ => false, - }; + has_rver_condition |= match condition { + // per MSC3932, we just need *any* room version condition to match + Condition::Known(KnownCondition::RoomVersionSupports { feature: _ }) => true, + _ => false, + }; + match self.match_condition(condition, user_id, display_name) { Ok(true) => {} Ok(false) => continue 'outer, From e08314e85c41352800c28783bf3633e0a124a03a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:44:34 +0000 Subject: [PATCH 5/7] Update changelog.d/14602.misc Co-authored-by: David Robertson --- changelog.d/14602.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/14602.misc b/changelog.d/14602.misc index 9bc294dfc587..092ba609d8b0 100644 --- a/changelog.d/14602.misc +++ b/changelog.d/14602.misc @@ -1 +1 @@ -Fix Rust ling CI. +Fix Rust lint CI. From 790be4a920a60f979f1b3394ab63994b6c36d0b2 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 15:49:27 +0000 Subject: [PATCH 6/7] Fix clippy --- rust/src/push/evaluator.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/src/push/evaluator.rs b/rust/src/push/evaluator.rs index fadb6690ee15..c901c0fbcc60 100644 --- a/rust/src/push/evaluator.rs +++ b/rust/src/push/evaluator.rs @@ -152,11 +152,11 @@ impl PushRuleEvaluator { let mut has_rver_condition = false; for condition in push_rule.conditions.iter() { - has_rver_condition |= match condition { + has_rver_condition |= matches!( + condition, // per MSC3932, we just need *any* room version condition to match - Condition::Known(KnownCondition::RoomVersionSupports { feature: _ }) => true, - _ => false, - }; + Condition::Known(KnownCondition::RoomVersionSupports { feature: _ }), + ); match self.match_condition(condition, user_id, display_name) { Ok(true) => {} From d2ea79b9aab14ccd526be7f94bfd06f15abe33b1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Dec 2022 16:01:25 +0000 Subject: [PATCH 7/7] Fix linting of benchmarks --- .github/workflows/tests.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e557095539b6..4cb2459b37a8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,7 +109,29 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --all-targets -- -D warnings + - run: cargo clippy -- -D warnings + + # We also lint against a nightly rustc so that we can lint the benchmark + # suite, which requires a nightly compiler. + lint-clippy-nightly: + runs-on: ubuntu-latest + needs: changes + if: ${{ needs.changes.outputs.rust == 'true' }} + + steps: + - uses: actions/checkout@v3 + + - name: Install Rust + # There don't seem to be versioned releases of this action per se: for each rust + # version there is a branch which gets constantly rebased on top of master. + # We pin to a specific commit for paranoia's sake. + uses: dtolnay/rust-toolchain@e645b0cf01249a964ec099494d38d2da0f0b349f + with: + toolchain: nightly-2022-12-01 + components: clippy + - uses: Swatinem/rust-cache@v2 + + - run: cargo clippy --all-features -- -D warnings lint-rustfmt: runs-on: ubuntu-latest