Fix many clippy warnings

This is because the tracing-attributes update made clippy look at those
again. I've removed the `too_many_lines` lint, as it's not really useful
and we ignore it most of the time anyway.
This commit is contained in:
Quentin Gliech
2025-07-30 14:49:38 +02:00
parent 15612abd9b
commit b8d23be313
39 changed files with 55 additions and 55 deletions

View File

@@ -26,6 +26,7 @@ all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
str_to_string = "deny"
too_many_lines = "allow"
[workspace.lints.rustdoc]
broken_intra_doc_links = "deny"

View File

@@ -368,7 +368,6 @@ where
{
type Rejection = ClientAuthorizationError;
#[allow(clippy::too_many_lines)]
async fn from_request(
req: Request<axum::body::Body>,
state: &S,

View File

@@ -26,7 +26,6 @@ const DOCS_BASE: &str = "https://element-hq.github.io/matrix-authentication-serv
pub(super) struct Options {}
impl Options {
#[allow(clippy::too_many_lines)]
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
let _span = info_span!("cli.doctor").entered();
info!(

View File

@@ -207,7 +207,6 @@ enum Subcommand {
}
impl Options {
#[allow(clippy::too_many_lines)]
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
use Subcommand as SC;
let clock = SystemClock::default();

View File

@@ -55,7 +55,6 @@ pub(super) struct Options {
}
impl Options {
#[allow(clippy::too_many_lines)]
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
let span = info_span!("cli.run.init").entered();
let mut shutdown = LifecycleManager::new()?;

View File

@@ -88,7 +88,6 @@ const NUM_WRITER_CONNECTIONS: usize = 8;
impl Options {
#[tracing::instrument("cli.syn2mas.run", skip_all)]
#[allow(clippy::too_many_lines)]
pub async fn run(self, figment: &Figment) -> anyhow::Result<ExitCode> {
if self.synapse_configuration_files.is_empty() {
error!("Please specify the path to the Synapse configuration file(s).");

View File

@@ -205,7 +205,6 @@ async fn log_response_middleware(
response
}
#[allow(clippy::too_many_lines)]
pub fn build_router(
state: AppState,
resources: &[HttpResource],

View File

@@ -9,7 +9,6 @@ use tokio::runtime::RuntimeMetrics;
use super::METER;
/// Install metrics for the tokio runtime.
#[allow(clippy::too_many_lines)]
pub fn observe(metrics: RuntimeMetrics) {
{
let metrics = metrics.clone();

View File

@@ -303,6 +303,7 @@ impl ConfigurationSection for SecretsConfig {
}
impl SecretsConfig {
#[expect(clippy::similar_names, reason = "Key type names are very similar")]
#[tracing::instrument(skip_all)]
pub(crate) async fn generate<R>(mut rng: R) -> anyhow::Result<Self>
where

View File

@@ -27,7 +27,6 @@ mod user_registration_tokens;
mod user_sessions;
mod users;
#[allow(clippy::too_many_lines)]
pub fn router<S>() -> ApiRouter<S>
where
S: Clone + Send + Sync + 'static,

View File

@@ -328,7 +328,6 @@ where
Router::new().merge(human_router).merge(api_router)
}
#[allow(clippy::too_many_lines)]
pub fn human_router<S>(templates: Templates) -> Router<S>
where
S: Clone + Send + Sync + 'static,

View File

@@ -109,7 +109,6 @@ fn resolve_response_mode(
fields(client.id = %params.auth.client_id),
skip_all,
)]
#[allow(clippy::too_many_lines)]
pub(crate) async fn get(
mut rng: BoxRng,
clock: BoxClock,

View File

@@ -35,7 +35,6 @@ struct DiscoveryResponse {
}
#[tracing::instrument(name = "handlers.oauth2.discovery.get", skip_all)]
#[allow(clippy::too_many_lines)]
pub(crate) async fn get(
State(key_store): State<Keystore>,
State(url_builder): State<UrlBuilder>,

View File

@@ -215,7 +215,6 @@ const SYNAPSE_ADMIN_SCOPE: ScopeToken = ScopeToken::from_static("urn:synapse:adm
fields(client.id = credentials.client_id()),
skip_all,
)]
#[allow(clippy::too_many_lines)]
pub(crate) async fn post(
clock: BoxClock,
State(http_client): State<reqwest::Client>,

View File

@@ -409,7 +409,6 @@ pub(crate) async fn post(
Ok((headers, Json(reply)))
}
#[allow(clippy::too_many_lines)] // TODO: refactor some parts out
async fn authorization_code_grant(
mut rng: &mut BoxRng,
clock: &impl Clock,
@@ -602,7 +601,6 @@ async fn authorization_code_grant(
Ok((params, repo))
}
#[allow(clippy::too_many_lines)]
async fn refresh_token_grant(
rng: &mut BoxRng,
clock: &impl Clock,

View File

@@ -625,7 +625,6 @@ mod tests {
);
}
#[allow(clippy::too_many_lines)]
#[tokio::test]
async fn hash_verify_and_upgrade() {
// Tests the whole password manager, by hashing a password and upgrading it

View File

@@ -165,6 +165,10 @@ impl MetadataCache {
///
/// This spawns a background task that will refresh the cache at the given
/// interval.
///
/// # Errors
///
/// Returns an error if the warm up task could not be started.
#[tracing::instrument(name = "metadata_cache.warm_up_and_run", skip_all)]
pub async fn warm_up_and_run<R: RepositoryAccess>(
&self,
@@ -237,6 +241,10 @@ impl MetadataCache {
}
/// Get the metadata for the given issuer.
///
/// # Errors
///
/// Returns an error if the metadata could not be retrieved.
#[tracing::instrument(name = "metadata_cache.get", fields(%issuer), skip_all)]
pub async fn get(
&self,
@@ -290,8 +298,6 @@ impl MetadataCache {
#[cfg(test)]
mod tests {
#![allow(clippy::too_many_lines)]
// XXX: sadly, we can't test HTTPS requests with wiremock, so we can only test
// 'insecure' discovery

View File

@@ -168,7 +168,7 @@ impl IntoResponse for RouteError {
fields(upstream_oauth_provider.id = %provider_id),
skip_all,
)]
#[allow(clippy::too_many_lines, clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments)]
pub(crate) async fn handler(
mut rng: BoxRng,
clock: BoxClock,

View File

@@ -119,7 +119,7 @@ pub(crate) async fn get(
}
#[tracing::instrument(name = "handlers.views.password_register.post", skip_all)]
#[allow(clippy::too_many_lines, clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments)]
pub(crate) async fn post(
mut rng: BoxRng,
clock: BoxClock,

View File

@@ -226,7 +226,7 @@ fn to_precision(number: f64, mut placeholder: Placeholder) -> String {
}
}
#[allow(clippy::too_many_lines, clippy::match_same_arms)]
#[allow(clippy::match_same_arms)]
fn format_value(value: &Value, placeholder: &Placeholder) -> Result<String, FormatError> {
match (value, &placeholder.type_specifier) {
(Value::Number(number), ts @ TypeSpecifier::BinaryNumber) => {

View File

@@ -169,7 +169,6 @@ pub fn json_schema_impl(
"{}".to_owned()
}}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {{
let enums = vec!["#,
section.key, section.key,

View File

@@ -71,7 +71,6 @@ impl File {
}
impl Display for File {
#[allow(clippy::too_many_lines)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(
f,

View File

@@ -148,7 +148,6 @@ impl schemars::JsonSchema for JsonWebSignatureAlg {
"JsonWebSignatureAlg".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -537,7 +536,6 @@ impl schemars::JsonSchema for JsonWebEncryptionAlg {
"JsonWebEncryptionAlg".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -887,7 +885,6 @@ impl schemars::JsonSchema for JsonWebEncryptionEnc {
"JsonWebEncryptionEnc".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1043,7 +1040,6 @@ impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm {
"JsonWebEncryptionCompressionAlgorithm".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1149,7 +1145,6 @@ impl schemars::JsonSchema for JsonWebKeyType {
"JsonWebKeyType".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1294,7 +1289,6 @@ impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve {
"JsonWebKeyEcEllipticCurve".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1439,7 +1433,6 @@ impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve {
"JsonWebKeyOkpEllipticCurve".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1574,7 +1567,6 @@ impl schemars::JsonSchema for JsonWebKeyUse {
"JsonWebKeyUse".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -1713,7 +1705,6 @@ impl schemars::JsonSchema for JsonWebKeyOperation {
"JsonWebKeyOperation".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---

View File

@@ -83,7 +83,6 @@ impl schemars::JsonSchema for OAuthAccessTokenType {
"OAuthAccessTokenType".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -215,7 +214,6 @@ impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType {
"OAuthAuthorizationEndpointResponseType".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -351,7 +349,6 @@ impl schemars::JsonSchema for OAuthTokenTypeHint {
"OAuthTokenTypeHint".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -477,7 +474,6 @@ impl schemars::JsonSchema for OAuthClientAuthenticationMethod {
"OAuthClientAuthenticationMethod".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---
@@ -602,7 +598,6 @@ impl schemars::JsonSchema for PkceCodeChallengeMethod {
"PkceCodeChallengeMethod".to_owned()
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let enums = vec![
// ---

View File

@@ -413,7 +413,6 @@ mod tests {
assert_eq!(candidates.len(), 1);
}
#[allow(clippy::too_many_lines)]
#[test]
fn load_keycloak_keys() {
let jwks = serde_json::json!({

View File

@@ -52,7 +52,6 @@ impl ParseError {
}
impl ProxyProtocolV1Info {
#[allow(clippy::too_many_lines)]
pub(super) fn parse<B>(buf: &mut B) -> Result<Self, ParseError>
where
B: Buf + AsRef<[u8]>,

View File

@@ -290,7 +290,6 @@ where
}
}
#[allow(clippy::too_many_lines)]
pub async fn run_servers<S, B>(
listeners: impl IntoIterator<Item = Server<S>>,
soft_shutdown_token: CancellationToken,

View File

@@ -440,7 +440,6 @@ impl ClientMetadata {
/// Will return `Err` if validation fails.
///
/// [OpenID Connect Dynamic Client Registration Spec 1.0]: https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
#[allow(clippy::too_many_lines)]
pub fn validate(self) -> Result<VerifiedClientMetadata, ClientMetadataVerificationError> {
let grant_types = self.grant_types();
let has_implicit = grant_types.contains(&GrantType::Implicit);
@@ -994,7 +993,6 @@ mod tests {
}
#[test]
#[allow(clippy::too_many_lines)]
fn validate_response_types() {
let mut metadata = valid_client_metadata();

View File

@@ -272,7 +272,6 @@ mod tests {
}
#[test]
#[allow(clippy::too_many_lines)]
fn deserialize_response_type() {
serde_json::from_str::<ResponseType>("\"\"").unwrap_err();

View File

@@ -130,7 +130,6 @@ impl ClientCredentials {
/// Apply these [`ClientCredentials`] to the given request with the given
/// form.
#[allow(clippy::too_many_lines)]
pub(crate) fn authenticated_form<T: Serialize>(
&self,
request: reqwest::RequestBuilder,

View File

@@ -197,6 +197,11 @@ pub struct PolicyFactory {
}
impl PolicyFactory {
/// Load the policy from the given data source.
///
/// # Errors
///
/// Returns an error if the policy can't be loaded or instantiated.
#[tracing::instrument(name = "policy.load", skip(source))]
pub async fn load(
mut source: impl AsyncRead + std::marker::Unpin,
@@ -283,6 +288,12 @@ impl PolicyFactory {
Ok(true)
}
/// Create a new policy instance.
///
/// # Errors
///
/// Returns an error if the policy can't be instantiated with the current
/// dynamic data.
#[tracing::instrument(name = "policy.instantiate", skip_all)]
pub async fn instantiate(&self) -> Result<Policy, InstantiateError> {
let data = self.dynamic_data.load();
@@ -336,6 +347,11 @@ pub enum EvaluationError {
}
impl Policy {
/// Evaluate the 'email' entrypoint.
///
/// # Errors
///
/// Returns an error if the policy engine fails to evaluate the entrypoint.
#[tracing::instrument(
name = "policy.evaluate_email",
skip_all,
@@ -355,6 +371,11 @@ impl Policy {
Ok(res)
}
/// Evaluate the 'register' entrypoint.
///
/// # Errors
///
/// Returns an error if the policy engine fails to evaluate the entrypoint.
#[tracing::instrument(
name = "policy.evaluate.register",
skip_all,
@@ -376,6 +397,11 @@ impl Policy {
Ok(res)
}
/// Evaluate the 'client_registration' entrypoint.
///
/// # Errors
///
/// Returns an error if the policy engine fails to evaluate the entrypoint.
#[tracing::instrument(skip(self))]
pub async fn evaluate_client_registration(
&mut self,
@@ -393,6 +419,11 @@ impl Policy {
Ok(res)
}
/// Evaluate the 'authorization_grant' entrypoint.
///
/// # Errors
///
/// Returns an error if the policy engine fails to evaluate the entrypoint.
#[tracing::instrument(
name = "policy.evaluate.authorization_grant",
skip_all,

View File

@@ -82,7 +82,6 @@ use priv_::{AppSessionLookup, AppSessionLookupIden};
impl TryFrom<AppSessionLookup> for AppSession {
type Error = DatabaseError;
#[allow(clippy::too_many_lines)]
fn try_from(value: AppSessionLookup) -> Result<Self, Self::Error> {
// This is annoying to do, but we have to match on all the fields to determine
// whether it's a compat session or an oauth2 session
@@ -257,7 +256,6 @@ fn split_filter(
impl AppSessionRepository for PgAppSessionRepository<'_> {
type Error = DatabaseError;
#[allow(clippy::too_many_lines)]
#[tracing::instrument(
name = "db.app_session.list",
fields(

View File

@@ -60,7 +60,6 @@ struct GrantLookup {
impl TryFrom<GrantLookup> for AuthorizationGrant {
type Error = DatabaseInconsistencyError;
#[allow(clippy::too_many_lines)]
fn try_from(value: GrantLookup) -> Result<Self, Self::Error> {
let id = value.oauth2_authorization_grant_id.into();
let scope: Scope = value.scope.parse().map_err(|e| {

View File

@@ -67,7 +67,6 @@ struct OAuth2ClientLookup {
impl TryInto<Client> for OAuth2ClientLookup {
type Error = DatabaseInconsistencyError;
#[allow(clippy::too_many_lines)] // TODO: refactor some of the field parsing
fn try_into(self) -> Result<Client, Self::Error> {
let id = Ulid::from(self.oauth2_client_id);
@@ -416,7 +415,6 @@ impl OAuth2ClientRepository for PgOAuth2ClientRepository<'_> {
),
err,
)]
#[allow(clippy::too_many_lines)]
async fn add(
&mut self,
rng: &mut (dyn RngCore + Send),

View File

@@ -77,7 +77,6 @@ struct ProviderLookup {
impl TryFrom<ProviderLookup> for UpstreamOAuthProvider {
type Error = DatabaseInconsistencyError;
#[allow(clippy::too_many_lines)]
fn try_from(value: ProviderLookup) -> Result<Self, Self::Error> {
let id = value.upstream_oauth_provider_id.into();
let scope = value.scope.parse().map_err(|e| {

View File

@@ -54,7 +54,6 @@ struct UserRegistrationTokenLookup {
}
impl Filter for UserRegistrationTokenFilter {
#[expect(clippy::too_many_lines)]
fn generate_condition(&self, _has_joins: bool) -> impl sea_query::IntoCondition {
sea_query::Condition::all()
.add_option(self.has_been_used().map(|has_been_used| {

View File

@@ -193,7 +193,6 @@ impl OidcProvider {
}
/// Map this Synapse OIDC provider config to a MAS upstream provider config.
#[expect(clippy::too_many_lines)]
pub(crate) fn into_mas_config(
self,
rng: &mut impl Rng,

View File

@@ -639,7 +639,7 @@ impl QueueWorker {
let now = clock.now();
for schedule in &self.schedules {
// Find the schedule status from the database
let Some(schedule_status) = schedules_status
let Some(status) = schedules_status
.iter()
.find(|s| s.schedule_name == schedule.schedule_name)
else {
@@ -651,13 +651,13 @@ impl QueueWorker {
};
// Figure out if we should schedule a new job
if let Some(next_time) = schedule_status.last_scheduled_at {
if let Some(next_time) = status.last_scheduled_at {
if next_time > now {
// We already have a job scheduled in the future, skip
continue;
}
if schedule_status.last_scheduled_job_completed == Some(false) {
if status.last_scheduled_job_completed == Some(false) {
// The last scheduled job has not completed yet, skip
continue;
}
@@ -960,7 +960,6 @@ impl JobTracker {
/// If `blocking` is `true`, this function will block until all the jobs
/// are finished. Otherwise, it will return as soon as it processed the
/// already finished jobs.
#[allow(clippy::too_many_lines)]
async fn process_jobs<E: std::error::Error + Send + Sync + 'static>(
&mut self,
rng: &mut (dyn RngCore + Send),

View File

@@ -135,6 +135,10 @@ fn is_hidden(entry: &DirEntry) -> bool {
impl Templates {
/// Load the templates from the given config
///
/// # Errors
///
/// Returns an error if the templates could not be loaded from disk.
#[tracing::instrument(
name = "templates.load",
skip_all,
@@ -254,6 +258,10 @@ impl Templates {
}
/// Reload the templates on disk
///
/// # Errors
///
/// Returns an error if the templates could not be reloaded from disk.
#[tracing::instrument(
name = "templates.reload",
skip_all,