From 9841b24a0cdb1388cb4a35ea9065e59deccf5d3a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 13 May 2026 10:56:07 +0200 Subject: [PATCH] Revert 1.95.0 clippy lints Let's do these in a separate PR. --- crates/cli/src/app_state.rs | 2 +- crates/cli/src/commands/server.rs | 2 +- crates/cli/src/lifecycle.rs | 2 +- crates/cli/src/server.rs | 4 ++-- crates/cli/src/util.rs | 2 +- crates/config/src/sections/database.rs | 4 ++-- crates/handlers/src/lib.rs | 6 ++--- crates/handlers/src/rate_limit.rs | 2 +- crates/handlers/src/test_utils.rs | 2 +- .../handlers/src/upstream_oauth2/template.rs | 12 ++++++---- crates/http/src/reqwest.rs | 2 +- crates/matrix-synapse/src/legacy.rs | 4 ++-- crates/oauth2-types/src/scope.rs | 4 +++- .../tests/it/requests/authorization_code.rs | 22 ++++++++----------- .../tests/it/requests/client_credentials.rs | 16 +++++++------- .../tests/it/requests/refresh_token.rs | 12 +++++----- .../tests/it/types/client_credentials.rs | 20 ++++++++--------- crates/tasks/src/cleanup/misc.rs | 2 +- crates/tasks/src/cleanup/oauth.rs | 8 +++---- crates/tasks/src/cleanup/sessions.rs | 12 +++++----- crates/tasks/src/cleanup/tokens.rs | 8 +++---- crates/tasks/src/cleanup/user.rs | 6 ++--- crates/templates/src/functions.rs | 2 +- 23 files changed, 79 insertions(+), 77 deletions(-) diff --git a/crates/cli/src/app_state.rs b/crates/cli/src/app_state.rs index 0641fb108..f211fc29c 100644 --- a/crates/cli/src/app_state.rs +++ b/crates/cli/src/app_state.rs @@ -100,7 +100,7 @@ impl AppState { if let Err(e) = metadata_cache .warm_up_and_run( &http_client, - std::time::Duration::from_mins(15), + std::time::Duration::from_secs(60 * 15), &mut repo, ) .await diff --git a/crates/cli/src/commands/server.rs b/crates/cli/src/commands/server.rs index 5aa3ac65e..b72d48111 100644 --- a/crates/cli/src/commands/server.rs +++ b/crates/cli/src/commands/server.rs @@ -203,7 +203,7 @@ impl Options { // Activity is flushed every minute let activity_tracker = ActivityTracker::new( PgRepositoryFactory::new(pool.clone()).boxed(), - Duration::from_mins(1), + Duration::from_secs(60), shutdown.task_tracker(), shutdown.soft_shutdown_token(), ); diff --git a/crates/cli/src/lifecycle.rs b/crates/cli/src/lifecycle.rs index 0fbd978b7..e44162936 100644 --- a/crates/cli/src/lifecycle.rs +++ b/crates/cli/src/lifecycle.rs @@ -83,7 +83,7 @@ impl LifecycleManager { let sigterm = tokio::signal::unix::signal(SignalKind::terminate())?; let sigint = tokio::signal::unix::signal(SignalKind::interrupt())?; let sighup = tokio::signal::unix::signal(SignalKind::hangup())?; - let timeout = Duration::from_mins(1); + let timeout = Duration::from_secs(60); let task_tracker = TaskTracker::new(); notify(&[sd_notify::NotifyState::MainPid(std::process::id())]); diff --git a/crates/cli/src/server.rs b/crates/cli/src/server.rs index 7a7590f54..25641c858 100644 --- a/crates/cli/src/server.rs +++ b/crates/cli/src/server.rs @@ -258,12 +258,12 @@ pub fn build_router( // Cache 404s for 5 minutes CacheControl::new() .with_public() - .with_max_age(Duration::from_mins(5)) + .with_max_age(Duration::from_secs(5 * 60)) } else { // Cache assets for 1 year CacheControl::new() .with_public() - .with_max_age(Duration::from_hours(8760)) + .with_max_age(Duration::from_secs(365 * 24 * 60 * 60)) .with_immutable() }; res.headers_mut().typed_insert(cache_control); diff --git a/crates/cli/src/util.rs b/crates/cli/src/util.rs index e8745c501..c3a8412f9 100644 --- a/crates/cli/src/util.rs +++ b/crates/cli/src/util.rs @@ -441,7 +441,7 @@ pub async fn load_policy_factory_dynamic_data_continuously( load_policy_factory_dynamic_data(&policy_factory, &*repository_factory).await?; task_tracker.spawn(async move { - let mut interval = tokio::time::interval(Duration::from_mins(1)); + let mut interval = tokio::time::interval(Duration::from_secs(60)); loop { tokio::select! { diff --git a/crates/config/src/sections/database.rs b/crates/config/src/sections/database.rs index 318ef7c32..4830a4016 100644 --- a/crates/config/src/sections/database.rs +++ b/crates/config/src/sections/database.rs @@ -29,12 +29,12 @@ fn default_connect_timeout() -> Duration { #[allow(clippy::unnecessary_wraps)] fn default_idle_timeout() -> Option { - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } #[allow(clippy::unnecessary_wraps)] fn default_max_lifetime() -> Option { - Some(Duration::from_mins(30)) + Some(Duration::from_secs(30 * 60)) } impl Default for DatabaseConfig { diff --git a/crates/handlers/src/lib.rs b/crates/handlers/src/lib.rs index 54560158f..0cb450f53 100644 --- a/crates/handlers/src/lib.rs +++ b/crates/handlers/src/lib.rs @@ -191,7 +191,7 @@ where CONTENT_LANGUAGE, CONTENT_TYPE, ]) - .max_age(Duration::from_hours(1)), + .max_age(Duration::from_secs(60 * 60)), ) } @@ -255,7 +255,7 @@ where // Swagger will send this header, so we have to allow it to avoid CORS errors HeaderName::from_static("x-requested-with"), ]) - .max_age(Duration::from_hours(1)), + .max_age(Duration::from_secs(60 * 60)), ) } @@ -326,7 +326,7 @@ where CONTENT_TYPE, HeaderName::from_static("x-requested-with"), ]) - .max_age(Duration::from_hours(1)), + .max_age(Duration::from_secs(60 * 60)), ); Router::new().merge(human_router).merge(api_router) diff --git a/crates/handlers/src/rate_limit.rs b/crates/handlers/src/rate_limit.rs index 370f5e751..0471e6351 100644 --- a/crates/handlers/src/rate_limit.rs +++ b/crates/handlers/src/rate_limit.rs @@ -145,7 +145,7 @@ impl Limiter { let this = self.clone(); tokio::spawn(async move { // Run the task every minute - let mut interval = tokio::time::interval(Duration::from_mins(1)); + let mut interval = tokio::time::interval(Duration::from_secs(60)); interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); loop { diff --git a/crates/handlers/src/test_utils.rs b/crates/handlers/src/test_utils.rs index 65257a306..619d995a7 100644 --- a/crates/handlers/src/test_utils.rs +++ b/crates/handlers/src/test_utils.rs @@ -241,7 +241,7 @@ impl TestState { let activity_tracker = ActivityTracker::new( PgRepositoryFactory::new(pool.clone()).boxed(), - std::time::Duration::from_mins(1), + std::time::Duration::from_secs(60), &task_tracker, shutdown_token.child_token(), ); diff --git a/crates/handlers/src/upstream_oauth2/template.rs b/crates/handlers/src/upstream_oauth2/template.rs index 655623a04..fcf24473a 100644 --- a/crates/handlers/src/upstream_oauth2/template.rs +++ b/crates/handlers/src/upstream_oauth2/template.rs @@ -134,10 +134,14 @@ fn b64encode(bytes: &[u8]) -> String { fn tlvdecode(bytes: &[u8]) -> Result, Error> { let mut iter = bytes.iter().copied(); let mut ret = HashMap::new(); - // TODO: this loop assumes the tag and the length are both single bytes, which - // is not always the case with protobufs. We should properly decode varints - // here. - while let Some(tag) = iter.next() { + loop { + // TODO: this assumes the tag and the length are both single bytes, which is not + // always the case with protobufs. We should properly decode varints + // here. + let Some(tag) = iter.next() else { + break; + }; + let len = iter .next() .ok_or_else(|| Error::new(ErrorKind::InvalidOperation, "Invalid ILV encoding"))?; diff --git a/crates/http/src/reqwest.rs b/crates/http/src/reqwest.rs index 13122fd52..a399a7423 100644 --- a/crates/http/src/reqwest.rs +++ b/crates/http/src/reqwest.rs @@ -102,7 +102,7 @@ pub fn client() -> reqwest::Client { .dns_resolver(Arc::new(TracingResolver::new())) .use_preconfigured_tls(tls_config) .user_agent(USER_AGENT) - .timeout(Duration::from_mins(1)) + .timeout(Duration::from_secs(60)) .connect_timeout(Duration::from_secs(30)) .build() .expect("failed to create HTTP client") diff --git a/crates/matrix-synapse/src/legacy.rs b/crates/matrix-synapse/src/legacy.rs index 2ef199566..b93298ceb 100644 --- a/crates/matrix-synapse/src/legacy.rs +++ b/crates/matrix-synapse/src/legacy.rs @@ -542,7 +542,7 @@ impl HomeserverConnection for SynapseConnection { .post(&format!("_synapse/admin/v1/deactivate/{encoded_mxid}")) .json(&SynapseDeactivateUserRequest { erase }) // Deactivation can take a while, so we set a longer timeout - .timeout(Duration::from_mins(5)) + .timeout(Duration::from_secs(60 * 5)) .send_traced() .await .context("Failed to deactivate user in Synapse")?; @@ -591,7 +591,7 @@ impl HomeserverConnection for SynapseConnection { match response.status() { StatusCode::CREATED | StatusCode::OK => Ok(()), - code => bail!("Unexpected HTTP code while reactivating user in Synapse: {code}"), + code => bail!("Unexpected HTTP code while reactivating user in Synapse: {code}",), } } diff --git a/crates/oauth2-types/src/scope.rs b/crates/oauth2-types/src/scope.rs index 3c7f3ffd9..f9832b5c0 100644 --- a/crates/oauth2-types/src/scope.rs +++ b/crates/oauth2-types/src/scope.rs @@ -165,7 +165,9 @@ impl Scope { /// Whether this `Scope` contains the given value. #[must_use] pub fn contains(&self, token: &str) -> bool { - ScopeToken::from_str(token).is_ok_and(|token| self.0.contains(&token)) + ScopeToken::from_str(token) + .map(|token| self.0.contains(&token)) + .unwrap_or(false) } /// Inserts the given token in this `Scope`. diff --git a/crates/oidc-client/tests/it/requests/authorization_code.rs b/crates/oidc-client/tests/it/requests/authorization_code.rs index 96057abf7..cc3f5b210 100644 --- a/crates/oidc-client/tests/it/requests/authorization_code.rs +++ b/crates/oidc-client/tests/it/requests/authorization_code.rs @@ -135,34 +135,30 @@ fn pass_full_authorization_url() { fn is_valid_token_endpoint_request(req: &Request) -> bool { let body = form_urlencoded::parse(&req.body).collect::>(); - if body - .get("client_id") - .as_ref() - .is_none_or(|s| *s != CLIENT_ID) - { + if body.get("client_id").filter(|s| *s == CLIENT_ID).is_none() { println!("Missing or wrong client ID"); return false; } if body .get("grant_type") - .as_ref() - .is_none_or(|s| *s != "authorization_code") + .filter(|s| *s == "authorization_code") + .is_none() { println!("Missing or wrong grant type"); return false; } if body .get("code") - .as_ref() - .is_none_or(|s| *s != AUTHORIZATION_CODE) + .filter(|s| *s == AUTHORIZATION_CODE) + .is_none() { println!("Missing or wrong authorization code"); return false; } if body .get("redirect_uri") - .as_ref() - .is_none_or(|s| *s != REDIRECT_URI) + .filter(|s| *s == REDIRECT_URI) + .is_none() { println!("Missing or wrong redirect URI"); return false; @@ -170,8 +166,8 @@ fn is_valid_token_endpoint_request(req: &Request) -> bool { if body .get("code_verifier") - .as_ref() - .is_none_or(|s| *s != CODE_VERIFIER) + .filter(|s| *s == CODE_VERIFIER) + .is_none() { println!("Missing or wrong code verifier"); return false; diff --git a/crates/oidc-client/tests/it/requests/client_credentials.rs b/crates/oidc-client/tests/it/requests/client_credentials.rs index 8bc3f61f9..00b3c774f 100644 --- a/crates/oidc-client/tests/it/requests/client_credentials.rs +++ b/crates/oidc-client/tests/it/requests/client_credentials.rs @@ -36,32 +36,32 @@ async fn pass_access_token_with_client_credentials() { if query_pairs .get("grant_type") - .as_ref() - .is_none_or(|s| *s != "client_credentials") + .filter(|s| *s == "client_credentials") + .is_none() { println!("Wrong or missing grant type"); return false; } if query_pairs .get("scope") - .as_ref() - .is_none_or(|s| *s != "profile") + .filter(|s| *s == "profile") + .is_none() { println!("Wrong or missing scope"); return false; } if query_pairs .get("client_id") - .as_ref() - .is_none_or(|s| *s != CLIENT_ID) + .filter(|s| *s == CLIENT_ID) + .is_none() { println!("Wrong or missing client ID"); return false; } if query_pairs .get("client_secret") - .as_ref() - .is_none_or(|s| *s != CLIENT_SECRET) + .filter(|s| *s == CLIENT_SECRET) + .is_none() { println!("Wrong or missing client secret"); return false; diff --git a/crates/oidc-client/tests/it/requests/refresh_token.rs b/crates/oidc-client/tests/it/requests/refresh_token.rs index 8ad5e2ec1..9b6e7c390 100644 --- a/crates/oidc-client/tests/it/requests/refresh_token.rs +++ b/crates/oidc-client/tests/it/requests/refresh_token.rs @@ -32,24 +32,24 @@ async fn pass_refresh_access_token() { if query_pairs .get("grant_type") - .as_ref() - .is_none_or(|s| *s != "refresh_token") + .filter(|s| *s == "refresh_token") + .is_none() { println!("Wrong or missing grant type"); return false; } if query_pairs .get("refresh_token") - .as_ref() - .is_none_or(|s| *s != REFRESH_TOKEN) + .filter(|s| *s == REFRESH_TOKEN) + .is_none() { println!("Wrong or missing refresh token"); return false; } if query_pairs .get("client_id") - .as_ref() - .is_none_or(|s| *s != CLIENT_ID) + .filter(|s| *s == CLIENT_ID) + .is_none() { println!("Wrong or missing client ID"); return false; diff --git a/crates/oidc-client/tests/it/types/client_credentials.rs b/crates/oidc-client/tests/it/types/client_credentials.rs index 0a3ef494f..c53a98e01 100644 --- a/crates/oidc-client/tests/it/types/client_credentials.rs +++ b/crates/oidc-client/tests/it/types/client_credentials.rs @@ -41,8 +41,8 @@ async fn pass_none() { if query_pairs .get("client_id") - .as_ref() - .is_none_or(|s| *s != CLIENT_ID) + .filter(|s| *s == CLIENT_ID) + .is_none() { println!("Wrong or missing client ID"); return false; @@ -132,16 +132,16 @@ async fn pass_client_secret_post() { if query_pairs .get("client_id") - .as_ref() - .is_none_or(|s| *s != CLIENT_ID) + .filter(|s| *s == CLIENT_ID) + .is_none() { println!("Wrong or missing client ID"); return false; } if query_pairs .get("client_secret") - .as_ref() - .is_none_or(|s| *s != CLIENT_SECRET) + .filter(|s| *s == CLIENT_SECRET) + .is_none() { println!("Wrong or missing client secret"); return false; @@ -194,8 +194,8 @@ async fn pass_client_secret_jwt() { } if query_pairs .get("client_assertion_type") - .as_ref() - .is_none_or(|s| *s != "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") + .filter(|s| *s == "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") + .is_none() { println!("Wrong or missing client assertion type"); return false; @@ -273,8 +273,8 @@ async fn pass_private_key_jwt() { } if query_pairs .get("client_assertion_type") - .as_ref() - .is_none_or(|s| *s != "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") + .filter(|s| *s == "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") + .is_none() { println!("Wrong or missing client assertion type"); return false; diff --git a/crates/tasks/src/cleanup/misc.rs b/crates/tasks/src/cleanup/misc.rs index 1b66acdef..52fd62e5c 100644 --- a/crates/tasks/src/cleanup/misc.rs +++ b/crates/tasks/src/cleanup/misc.rs @@ -58,7 +58,7 @@ impl RunnableJob for CleanupQueueJobsJob { } fn timeout(&self) -> Option { - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } diff --git a/crates/tasks/src/cleanup/oauth.rs b/crates/tasks/src/cleanup/oauth.rs index da80b3b25..2a201d4df 100644 --- a/crates/tasks/src/cleanup/oauth.rs +++ b/crates/tasks/src/cleanup/oauth.rs @@ -70,7 +70,7 @@ impl RunnableJob for CleanupOAuthAuthorizationGrantsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -123,7 +123,7 @@ impl RunnableJob for CleanupOAuthDeviceCodeGrantsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -167,7 +167,7 @@ impl RunnableJob for CleanupUpstreamOAuthSessionsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -211,6 +211,6 @@ impl RunnableJob for CleanupUpstreamOAuthLinksJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } diff --git a/crates/tasks/src/cleanup/sessions.rs b/crates/tasks/src/cleanup/sessions.rs index c9abdfe0b..0a11a6b99 100644 --- a/crates/tasks/src/cleanup/sessions.rs +++ b/crates/tasks/src/cleanup/sessions.rs @@ -65,7 +65,7 @@ impl RunnableJob for CleanupFinishedCompatSessionsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -113,7 +113,7 @@ impl RunnableJob for CleanupFinishedOAuth2SessionsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -162,7 +162,7 @@ impl RunnableJob for CleanupFinishedUserSessionsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -203,7 +203,7 @@ impl RunnableJob for CleanupInactiveOAuth2SessionIpsJob { } fn timeout(&self) -> Option { - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -244,7 +244,7 @@ impl RunnableJob for CleanupInactiveCompatSessionIpsJob { } fn timeout(&self) -> Option { - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -285,6 +285,6 @@ impl RunnableJob for CleanupInactiveUserSessionIpsJob { } fn timeout(&self) -> Option { - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } diff --git a/crates/tasks/src/cleanup/tokens.rs b/crates/tasks/src/cleanup/tokens.rs index 4344bd5ef..dd91de2b9 100644 --- a/crates/tasks/src/cleanup/tokens.rs +++ b/crates/tasks/src/cleanup/tokens.rs @@ -63,7 +63,7 @@ impl RunnableJob for CleanupRevokedOAuthAccessTokensJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -115,7 +115,7 @@ impl RunnableJob for CleanupExpiredOAuthAccessTokensJob { } fn timeout(&self) -> Option { - Some(Duration::from_mins(1)) + Some(Duration::from_secs(60)) } } @@ -162,7 +162,7 @@ impl RunnableJob for CleanupRevokedOAuthRefreshTokensJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -209,6 +209,6 @@ impl RunnableJob for CleanupConsumedOAuthRefreshTokensJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } diff --git a/crates/tasks/src/cleanup/user.rs b/crates/tasks/src/cleanup/user.rs index 73e8602d7..d682c1b51 100644 --- a/crates/tasks/src/cleanup/user.rs +++ b/crates/tasks/src/cleanup/user.rs @@ -69,7 +69,7 @@ impl RunnableJob for CleanupUserRegistrationsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -122,7 +122,7 @@ impl RunnableJob for CleanupUserRecoverySessionsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } @@ -176,6 +176,6 @@ impl RunnableJob for CleanupUserEmailAuthenticationsJob { fn timeout(&self) -> Option { // This job runs every hour, so having it running it for 10 minutes is fine - Some(Duration::from_mins(10)) + Some(Duration::from_secs(10 * 60)) } } diff --git a/crates/templates/src/functions.rs b/crates/templates/src/functions.rs index 8947c518a..f860580d8 100644 --- a/crates/templates/src/functions.rs +++ b/crates/templates/src/functions.rs @@ -526,7 +526,7 @@ impl Object for IncludeAsset { // When a JSON is included at the top level (a translation), we preload it let src = main.src(assets_base); if tracker.mark_preloaded(&src) { - writeln!(output, r#""#).unwrap(); + writeln!(output, r#""#,).unwrap(); } }