From 6b2985abac64a20af0cab5c20d305e7fb8d04c9a Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 1 Nov 2024 16:13:02 -0400 Subject: [PATCH] tree: fix clippy warnings This is a mix of both new and old clippy warnings. Just doing it in one commit to make it easier. --- commons/src/policy.rs | 2 +- fcos-graph-builder/src/scraper.rs | 11 ++++++----- fcos-graph-builder/src/settings.rs | 2 +- fcos-policy-engine/src/main.rs | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/commons/src/policy.rs b/commons/src/policy.rs index d39f9ed..10e33ab 100644 --- a/commons/src/policy.rs +++ b/commons/src/policy.rs @@ -30,7 +30,7 @@ pub fn throttle_rollouts(input: Graph, client_wariness: f64) -> Graph { for (index, release) in graph.nodes.iter().enumerate() { // Skip if this release is not being rolled out. - if release.metadata.get(metadata::ROLLOUT).is_none() { + if !release.metadata.contains_key(metadata::ROLLOUT) { continue; }; diff --git a/fcos-graph-builder/src/scraper.rs b/fcos-graph-builder/src/scraper.rs index 2fb7f22..3aacef3 100644 --- a/fcos-graph-builder/src/scraper.rs +++ b/fcos-graph-builder/src/scraper.rs @@ -220,8 +220,9 @@ impl Handler for Scraper { g.into_iter() .map(|(arch, graph)| (arch, false, graph)) .chain(oci_g.into_iter().map(|(arch, graph)| (arch, true, graph))) - .map(|(arch, oci, graph)| actor.update_cached_graph(arch, oci, graph)) - .collect() + .try_for_each(|(arch, oci, graph)| { + actor.update_cached_graph(arch, oci, graph) + }) }); if let Err(e) = res { log::error!("transient scraping failure: {}", e); @@ -265,15 +266,15 @@ impl Handler for Scraper { }; if let Some(graph) = target_graphmap.get(&msg.scope.basearch) { crate::CACHED_GRAPH_REQUESTS - .with_label_values(&[&msg.scope.basearch, &msg.scope.stream, &graph_type]) + .with_label_values(&[&msg.scope.basearch, &msg.scope.stream, graph_type]) .inc(); Box::new(actix::fut::ok(graph.clone())) } else { - return Box::new(actix::fut::err(format_err!( + Box::new(actix::fut::err(format_err!( "unexpected basearch '{}'", msg.scope.basearch - ))); + ))) } } } diff --git a/fcos-graph-builder/src/settings.rs b/fcos-graph-builder/src/settings.rs index 55574be..40c7913 100644 --- a/fcos-graph-builder/src/settings.rs +++ b/fcos-graph-builder/src/settings.rs @@ -51,7 +51,7 @@ impl Default for ServiceSettings { origin_allowlist: None, ip_addr: Self::DEFAULT_GB_SERVICE_ADDR.into(), port: Self::DEFAULT_GB_SERVICE_PORT, - streams: Self::DEFAULT_STREAMS.iter().map(|&t| t).collect(), + streams: Self::DEFAULT_STREAMS.iter().copied().collect(), } } } diff --git a/fcos-policy-engine/src/main.rs b/fcos-policy-engine/src/main.rs index 5d6a55b..68f7bea 100644 --- a/fcos-policy-engine/src/main.rs +++ b/fcos-policy-engine/src/main.rs @@ -190,7 +190,7 @@ fn compute_wariness(params: &GraphQuery) -> f64 { .unwrap_or_default() .parse::() { - let wariness = input.max(0.0).min(1.0); + let wariness = input.clamp(0.0, 1.0); return wariness; } @@ -207,9 +207,9 @@ fn compute_wariness(params: &GraphQuery) -> f64 { uuid.hash(&mut hasher); let digest = hasher.finish(); // Scale down. - let scaled = (digest as f64) / (std::u64::MAX as f64); + let scaled = (digest as f64) / (u64::MAX as f64); // Clamp within limits. - scaled.max(COMPUTED_MIN).min(COMPUTED_MAX) + scaled.clamp(COMPUTED_MIN, COMPUTED_MAX) }; wariness