diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7855e6d55..908d2ecba 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.88.0" +channel = "1.89.0" components = ["rustfmt", "clippy"] diff --git a/src/cdn.rs b/src/cdn.rs index 25aa294c7..5dae03b92 100644 --- a/src/cdn.rs +++ b/src/cdn.rs @@ -381,10 +381,9 @@ pub(crate) async fn handle_queued_invalidation_requests( if let Some(status) = cdn .invalidation_status(distribution_id, &row.cdn_reference) .await? + && !status.completed { - if !status.completed { - active_invalidations.push(status); - } + active_invalidations.push(status); } } @@ -453,11 +452,10 @@ pub(crate) async fn handle_queued_invalidation_requests( ) .fetch_one(&mut *conn) .await? + && (now - min_queued).to_std().unwrap_or_default() >= config.cdn_max_queued_age { - if (now - min_queued).to_std().unwrap_or_default() >= config.cdn_max_queued_age { - full_invalidation(cdn, metrics, conn, distribution_id).await?; - return Ok(()); - } + full_invalidation(cdn, metrics, conn, distribution_id).await?; + return Ok(()); } // create new an invalidation for the queued path patterns diff --git a/src/db/add_package.rs b/src/db/add_package.rs index f42d2344a..dcff5b1e3 100644 --- a/src/db/add_package.rs +++ b/src/db/add_package.rs @@ -649,6 +649,7 @@ mod test { use crate::test::*; use crate::utils::CargoMetadata; use chrono::NaiveDate; + use std::slice; use test_case::test_case; #[test] @@ -965,7 +966,7 @@ mod test { kind: OwnerKind::User, }; - update_owners_in_database(&mut conn, &[owner1.clone()], crate_id).await?; + update_owners_in_database(&mut conn, slice::from_ref(&owner1), crate_id).await?; let owner_def = sqlx::query!( r#"SELECT login, avatar, kind as "kind: OwnerKind" @@ -1005,7 +1006,7 @@ mod test { kind: OwnerKind::User, }; - update_owners_in_database(&mut conn, &[owner1.clone()], crate_id).await?; + update_owners_in_database(&mut conn, slice::from_ref(&owner1), crate_id).await?; let owner_def = sqlx::query!( r#"SELECT login, avatar, kind as "kind: OwnerKind" @@ -1056,7 +1057,7 @@ mod test { avatar: "avatar2".into(), kind: OwnerKind::Team, }; - update_owners_in_database(&mut conn, &[updated_owner.clone()], crate_id).await?; + update_owners_in_database(&mut conn, slice::from_ref(&updated_owner), crate_id).await?; let owner_def = sqlx::query!(r#"SELECT login, avatar, kind as "kind: OwnerKind" FROM owners"#) diff --git a/src/docbuilder/rustwide_builder.rs b/src/docbuilder/rustwide_builder.rs index effb74d1f..0b215ee34 100644 --- a/src/docbuilder/rustwide_builder.rs +++ b/src/docbuilder/rustwide_builder.rs @@ -586,8 +586,8 @@ impl RustwideBuilder { self.execute_build(build_id, name, version, default_target, true, build, &limits, &metadata, false, collect_metrics)?; } - if res.result.successful { - if let Some(name) = res.cargo_metadata.root().library_name() { + if res.result.successful + && let Some(name) = res.cargo_metadata.root().library_name() { let host_target = build.host_target_dir(); has_docs = host_target .join(default_target) @@ -595,7 +595,6 @@ impl RustwideBuilder { .join(name) .is_dir(); } - } let mut target_build_logs = HashMap::new(); let documentation_size = if has_docs { @@ -1077,19 +1076,18 @@ impl RustwideBuilder { }) }; - if collect_metrics { - if let Some(compiler_metric_target_dir) = &self.config.compiler_metrics_collection_path - { - let metric_output = build.host_target_dir().join("metrics/"); - info!( - "found {} files in metric dir, copy over to {} (exists: {})", - fs::read_dir(&metric_output)?.count(), - &compiler_metric_target_dir.to_string_lossy(), - &compiler_metric_target_dir.exists(), - ); - copy_dir_all(&metric_output, compiler_metric_target_dir)?; - fs::remove_dir_all(&metric_output)?; - } + if collect_metrics + && let Some(compiler_metric_target_dir) = &self.config.compiler_metrics_collection_path + { + let metric_output = build.host_target_dir().join("metrics/"); + info!( + "found {} files in metric dir, copy over to {} (exists: {})", + fs::read_dir(&metric_output)?.count(), + &compiler_metric_target_dir.to_string_lossy(), + &compiler_metric_target_dir.exists(), + ); + copy_dir_all(&metric_output, compiler_metric_target_dir)?; + fs::remove_dir_all(&metric_output)?; } // For proc-macros, cargo will put the output in `target/doc`. diff --git a/src/storage/s3.rs b/src/storage/s3.rs index c3aa69eb2..fcf257d4b 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -51,16 +51,16 @@ where match self { Ok(result) => Ok(result), Err(err) => { - if let Some(err_code) = err.code() { - if NOT_FOUND_ERROR_CODES.contains(&err_code) { - return Err(super::PathNotFoundError.into()); - } + if let Some(err_code) = err.code() + && NOT_FOUND_ERROR_CODES.contains(&err_code) + { + return Err(super::PathNotFoundError.into()); } - if let SdkError::ServiceError(err) = &err { - if err.raw().status().as_u16() == http::StatusCode::NOT_FOUND.as_u16() { - return Err(super::PathNotFoundError.into()); - } + if let SdkError::ServiceError(err) = &err + && err.raw().status().as_u16() == http::StatusCode::NOT_FOUND.as_u16() + { + return Err(super::PathNotFoundError.into()); } Err(err.into()) diff --git a/src/test/mod.rs b/src/test/mod.rs index 8b1a62e7a..e137943d5 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -239,11 +239,11 @@ impl AxumRouterTestExt for axum::Router { let mut path = path.to_owned(); for _ in 0..=10 { let response = self.get(&path).await?; - if response.status().is_redirection() { - if let Some(target) = response.redirect_target() { - path = target.to_owned(); - continue; - } + if response.status().is_redirection() + && let Some(target) = response.redirect_target() + { + path = target.to_owned(); + continue; } return Ok(response); } @@ -409,10 +409,10 @@ impl TestEnvironment { .expect("failed to cleanup after tests"); } - if let Some(config) = self.config.get() { - if config.local_archive_cache_path.exists() { - fs::remove_dir_all(&config.local_archive_cache_path).unwrap(); - } + if let Some(config) = self.config.get() + && config.local_archive_cache_path.exists() + { + fs::remove_dir_all(&config.local_archive_cache_path).unwrap(); } } @@ -610,7 +610,7 @@ impl TestEnvironment { .expect("could not build axum app") } - pub(crate) async fn fake_release(&self) -> fakes::FakeRelease { + pub(crate) async fn fake_release(&self) -> fakes::FakeRelease<'_> { fakes::FakeRelease::new(self.async_db().await, self.async_storage().await) } } diff --git a/src/utils/consistency/diff.rs b/src/utils/consistency/diff.rs index 694d24b11..78e929b60 100644 --- a/src/utils/consistency/diff.rs +++ b/src/utils/consistency/diff.rs @@ -65,14 +65,14 @@ where // is coming from the build queue, not the `releases` // table. // In this case, we skip this check. - if let Some(db_yanked) = db_release.yanked { - if db_yanked != index_yanked { - result.push(Difference::ReleaseYank( - db_crate.name.clone(), - db_release.version.clone(), - index_yanked, - )); - } + if let Some(db_yanked) = db_release.yanked + && db_yanked != index_yanked + { + result.push(Difference::ReleaseYank( + db_crate.name.clone(), + db_release.version.clone(), + index_yanked, + )); } } Left(db_release) => result.push(Difference::ReleaseNotInIndex( diff --git a/src/utils/consistency/mod.rs b/src/utils/consistency/mod.rs index d60d8c292..8043c0975 100644 --- a/src/utils/consistency/mod.rs +++ b/src/utils/consistency/mod.rs @@ -99,53 +99,47 @@ where match difference { diff::Difference::CrateNotInIndex(name) => { - if !dry_run { - if let Err(err) = delete::delete_crate(&mut conn, &storage, &config, name).await - { - warn!("{:?}", err); - } + if !dry_run + && let Err(err) = delete::delete_crate(&mut conn, &storage, &config, name).await + { + warn!("{:?}", err); } result.crates_deleted += 1; } diff::Difference::CrateNotInDb(name, versions) => { for version in versions { - if !dry_run { - if let Err(err) = build_queue + if !dry_run + && let Err(err) = build_queue .add_crate(name, version, BUILD_PRIORITY, None) .await - { - warn!("{:?}", err); - } + { + warn!("{:?}", err); } result.builds_queued += 1; } } diff::Difference::ReleaseNotInIndex(name, version) => { - if !dry_run { - if let Err(err) = + if !dry_run + && let Err(err) = delete::delete_version(&mut conn, &storage, &config, name, version).await - { - warn!("{:?}", err); - } + { + warn!("{:?}", err); } result.releases_deleted += 1; } diff::Difference::ReleaseNotInDb(name, version) => { - if !dry_run { - if let Err(err) = build_queue + if !dry_run + && let Err(err) = build_queue .add_crate(name, version, BUILD_PRIORITY, None) .await - { - warn!("{:?}", err); - } + { + warn!("{:?}", err); } result.builds_queued += 1; } diff::Difference::ReleaseYank(name, version, yanked) => { - if !dry_run { - if let Err(err) = build_queue.set_yanked(name, version, *yanked).await { - warn!("{:?}", err); - } + if !dry_run && let Err(err) = build_queue.set_yanked(name, version, *yanked).await { + warn!("{:?}", err); } result.yanks_corrected += 1; } diff --git a/src/web/extractors.rs b/src/web/extractors.rs index d43da55d2..639e84aa0 100644 --- a/src/web/extractors.rs +++ b/src/web/extractors.rs @@ -129,10 +129,10 @@ where parts: &mut Parts, _state: &S, ) -> Result, Self::Rejection> { - if let Some((_rest, last_component)) = parts.uri.path().rsplit_once('/') { - if let Some((_rest, ext)) = last_component.rsplit_once('.') { - return Ok(Some(PathFileExtension(ext.to_string()))); - } + if let Some((_rest, last_component)) = parts.uri.path().rsplit_once('/') + && let Some((_rest, ext)) = last_component.rsplit_once('.') + { + return Ok(Some(PathFileExtension(ext.to_string()))); } Ok(None) diff --git a/src/web/highlight.rs b/src/web/highlight.rs index 418471ecf..0c6bb9a10 100644 --- a/src/web/highlight.rs +++ b/src/web/highlight.rs @@ -55,10 +55,10 @@ fn select_syntax( default: Option<&str>, ) -> &'static SyntaxReference { name.and_then(|name| { - if name.is_empty() { - if let Some(default) = default { - return SYNTAXES.find_syntax_by_token(default); - } + if name.is_empty() + && let Some(default) = default + { + return SYNTAXES.find_syntax_by_token(default); } SYNTAXES.find_syntax_by_token(name).or_else(|| { name.rsplit_once('.') diff --git a/src/web/mod.rs b/src/web/mod.rs index 8a879525d..605d58e35 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -257,7 +257,7 @@ fn semver_match<'a, F: Fn(&Release) -> bool>( // So when we only have pre-releases, `VersionReq::STAR` would lead to an // empty result. // In this case we just return the latest prerelease instead of nothing. - return releases.iter().find(|release| filter(release)); + releases.iter().find(|release| filter(release)) } else { None } diff --git a/src/web/routes.rs b/src/web/routes.rs index d24876e96..c6782b4cd 100644 --- a/src/web/routes.rs +++ b/src/web/routes.rs @@ -70,17 +70,16 @@ async fn block_blacklisted_prefixes_middleware( request: AxumHttpRequest, next: Next, ) -> impl IntoResponse { - if let Some(first_component) = request.uri().path().trim_matches('/').split('/').next() { - if !first_component.is_empty() - && (INTERNAL_PREFIXES.binary_search(&first_component).is_ok()) - { - debug!( - first_component = first_component, - uri = ?request.uri(), - "blocking blacklisted prefix" - ); - return AxumNope::CrateNotFound.into_response(); - } + if let Some(first_component) = request.uri().path().trim_matches('/').split('/').next() + && !first_component.is_empty() + && (INTERNAL_PREFIXES.binary_search(&first_component).is_ok()) + { + debug!( + first_component = first_component, + uri = ?request.uri(), + "blocking blacklisted prefix" + ); + return AxumNope::CrateNotFound.into_response(); } next.run(request).await diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 36ea3973d..9959b1210 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -233,28 +233,27 @@ pub(crate) async fn rustdoc_redirector_handler( // global static assets for older builds are served from the root, which ends up // in this handler as `params.name`. - if let Some((_, extension)) = params.name.rsplit_once('.') { - if ["css", "js", "png", "svg", "woff", "woff2"] + if let Some((_, extension)) = params.name.rsplit_once('.') + && ["css", "js", "png", "svg", "woff", "woff2"] .binary_search(&extension) .is_ok() - { - return try_serve_legacy_toolchain_asset(storage, params.name) - .instrument(info_span!("serve static asset")) - .await; - } + { + return try_serve_legacy_toolchain_asset(storage, params.name) + .instrument(info_span!("serve static asset")) + .await; } - if let Some((_, extension)) = uri.path().rsplit_once('.') { - if extension == "ico" { - // redirect all ico requests - // originally from: - // https://github.com/rust-lang/docs.rs/commit/f3848a34c391841a2516a9e6ad1f80f6f490c6d0 - return Ok(axum_cached_redirect( - "/-/static/favicon.ico", - CachePolicy::ForeverInCdnAndBrowser, - )? - .into_response()); - } + if let Some((_, extension)) = uri.path().rsplit_once('.') + && extension == "ico" + { + // redirect all ico requests + // originally from: + // https://github.com/rust-lang/docs.rs/commit/f3848a34c391841a2516a9e6ad1f80f6f490c6d0 + return Ok(axum_cached_redirect( + "/-/static/favicon.ico", + CachePolicy::ForeverInCdnAndBrowser, + )? + .into_response()); } let (crate_name, path_in_crate) = match params.name.split_once("::") { @@ -285,48 +284,45 @@ pub(crate) async fn rustdoc_redirector_handler( let crate_name = matched_release.name.clone(); // we might get requests to crate-specific JS/CSS files here. - if let Some(ref target) = params.target { - if target.ends_with(".js") || target.ends_with(".css") { - // this URL is actually from a crate-internal path, serve it there instead - return async { - let krate = CrateDetails::from_matched_release(&mut conn, matched_release).await?; - - match storage - .stream_rustdoc_file( - &crate_name, - &krate.version.to_string(), - krate.latest_build_id, - target, - krate.archive_storage, - ) - .await - { - Ok(blob) => Ok(StreamingFile(blob).into_response()), - Err(err) => { - if !matches!(err.downcast_ref(), Some(AxumNope::ResourceNotFound)) - && !matches!( - err.downcast_ref(), - Some(crate::storage::PathNotFoundError) - ) - { - debug!(?target, ?err, "got error serving file"); - } - // FIXME: we sometimes still get requests for toolchain - // specific static assets under the crate/version/ path. - // This is fixed in rustdoc, but pending a rebuild for - // docs that were affected by this bug. - // https://github.com/rust-lang/docs.rs/issues/1979 - if target.starts_with("search-") || target.starts_with("settings-") { - try_serve_legacy_toolchain_asset(storage, target).await - } else { - Err(err.into()) - } + if let Some(ref target) = params.target + && (target.ends_with(".js") || target.ends_with(".css")) + { + // this URL is actually from a crate-internal path, serve it there instead + return async { + let krate = CrateDetails::from_matched_release(&mut conn, matched_release).await?; + + match storage + .stream_rustdoc_file( + &crate_name, + &krate.version.to_string(), + krate.latest_build_id, + target, + krate.archive_storage, + ) + .await + { + Ok(blob) => Ok(StreamingFile(blob).into_response()), + Err(err) => { + if !matches!(err.downcast_ref(), Some(AxumNope::ResourceNotFound)) + && !matches!(err.downcast_ref(), Some(crate::storage::PathNotFoundError)) + { + debug!(?target, ?err, "got error serving file"); + } + // FIXME: we sometimes still get requests for toolchain + // specific static assets under the crate/version/ path. + // This is fixed in rustdoc, but pending a rebuild for + // docs that were affected by this bug. + // https://github.com/rust-lang/docs.rs/issues/1979 + if target.starts_with("search-") || target.starts_with("settings-") { + try_serve_legacy_toolchain_asset(storage, target).await + } else { + Err(err.into()) } } } - .instrument(info_span!("serve asset for crate")) - .await; } + .instrument(info_span!("serve asset for crate")) + .await; } let matched_release = matched_release.into_canonical_req_version(); @@ -849,10 +845,10 @@ pub(crate) async fn target_redirect_handler( pieces.remove(0); } - if let Some(last) = pieces.last_mut() { - if last.is_empty() { - *last = "index.html".to_string(); - } + if let Some(last) = pieces.last_mut() + && last.is_empty() + { + *last = "index.html".to_string(); } pieces.join("/") diff --git a/src/web/sitemap.rs b/src/web/sitemap.rs index ad0c2e824..6be1ffe18 100644 --- a/src/web/sitemap.rs +++ b/src/web/sitemap.rs @@ -61,10 +61,10 @@ pub(crate) async fn sitemap_handler( ) -> AxumResult { if letter.len() != 1 { return Err(AxumNope::ResourceNotFound); - } else if let Some(ch) = letter.chars().next() { - if !(ch.is_ascii_lowercase()) { - return Err(AxumNope::ResourceNotFound); - } + } else if let Some(ch) = letter.chars().next() + && !(ch.is_ascii_lowercase()) + { + return Err(AxumNope::ResourceNotFound); } let releases: Vec<_> = sqlx::query!(