mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Fix Rust lint CI (#14602)
This commit is contained in:
parent
acea4d7a2f
commit
890e5f610e
4 changed files with 47 additions and 16 deletions
24
.github/workflows/tests.yml
vendored
24
.github/workflows/tests.yml
vendored
|
@ -109,7 +109,29 @@ jobs:
|
||||||
components: clippy
|
components: clippy
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- run: cargo clippy
|
- 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:
|
lint-rustfmt:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
1
changelog.d/14602.misc
Normal file
1
changelog.d/14602.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix Rust lint CI.
|
|
@ -33,10 +33,12 @@ fn bench_match_exact(b: &mut Bencher) {
|
||||||
let eval = PushRuleEvaluator::py_new(
|
let eval = PushRuleEvaluator::py_new(
|
||||||
flattened_keys,
|
flattened_keys,
|
||||||
10,
|
10,
|
||||||
0,
|
Some(0),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
true,
|
true,
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -67,10 +69,12 @@ fn bench_match_word(b: &mut Bencher) {
|
||||||
let eval = PushRuleEvaluator::py_new(
|
let eval = PushRuleEvaluator::py_new(
|
||||||
flattened_keys,
|
flattened_keys,
|
||||||
10,
|
10,
|
||||||
0,
|
Some(0),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
true,
|
true,
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -101,10 +105,12 @@ fn bench_match_word_miss(b: &mut Bencher) {
|
||||||
let eval = PushRuleEvaluator::py_new(
|
let eval = PushRuleEvaluator::py_new(
|
||||||
flattened_keys,
|
flattened_keys,
|
||||||
10,
|
10,
|
||||||
0,
|
Some(0),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
true,
|
true,
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -135,10 +141,12 @@ fn bench_eval_message(b: &mut Bencher) {
|
||||||
let eval = PushRuleEvaluator::py_new(
|
let eval = PushRuleEvaluator::py_new(
|
||||||
flattened_keys,
|
flattened_keys,
|
||||||
10,
|
10,
|
||||||
0,
|
Some(0),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
true,
|
true,
|
||||||
|
vec![],
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::push::{PushRule, PushRules};
|
|
||||||
use anyhow::{Context, Error};
|
use anyhow::{Context, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
|
@ -98,6 +96,7 @@ pub struct PushRuleEvaluator {
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
impl PushRuleEvaluator {
|
impl PushRuleEvaluator {
|
||||||
/// Create a new `PushRuleEvaluator`. See struct docstring for details.
|
/// Create a new `PushRuleEvaluator`. See struct docstring for details.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[new]
|
#[new]
|
||||||
pub fn py_new(
|
pub fn py_new(
|
||||||
flattened_keys: BTreeMap<String, String>,
|
flattened_keys: BTreeMap<String, String>,
|
||||||
|
@ -153,15 +152,12 @@ impl PushRuleEvaluator {
|
||||||
let mut has_rver_condition = false;
|
let mut has_rver_condition = false;
|
||||||
|
|
||||||
for condition in push_rule.conditions.iter() {
|
for condition in push_rule.conditions.iter() {
|
||||||
has_rver_condition = has_rver_condition
|
has_rver_condition |= matches!(
|
||||||
|| match condition {
|
condition,
|
||||||
Condition::Known(known) => match known {
|
// per MSC3932, we just need *any* room version condition to match
|
||||||
// per MSC3932, we just need *any* room version condition to match
|
Condition::Known(KnownCondition::RoomVersionSupports { feature: _ }),
|
||||||
KnownCondition::RoomVersionSupports { feature: _ } => true,
|
);
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
match self.match_condition(condition, user_id, display_name) {
|
match self.match_condition(condition, user_id, display_name) {
|
||||||
Ok(true) => {}
|
Ok(true) => {}
|
||||||
Ok(false) => continue 'outer,
|
Ok(false) => continue 'outer,
|
||||||
|
@ -444,6 +440,10 @@ fn push_rule_evaluator() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_requires_room_version_supports_condition() {
|
fn test_requires_room_version_supports_condition() {
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use crate::push::{PushRule, PushRules};
|
||||||
|
|
||||||
let mut flattened_keys = BTreeMap::new();
|
let mut flattened_keys = BTreeMap::new();
|
||||||
flattened_keys.insert("content.body".to_string(), "foo bar bob hello".to_string());
|
flattened_keys.insert("content.body".to_string(), "foo bar bob hello".to_string());
|
||||||
let flags = vec![RoomVersionFeatures::ExtensibleEvents.as_str().to_string()];
|
let flags = vec![RoomVersionFeatures::ExtensibleEvents.as_str().to_string()];
|
||||||
|
|
Loading…
Reference in a new issue