about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Schouten <mhkbst@gmail.com>2025-07-11 07:15:20 +0000
committerMarijn Schouten <mhkbst@gmail.com>2025-07-11 07:15:20 +0000
commitba3b7a7d9c5908633c26145e78166b0d97e518ad (patch)
tree30d8a078d03e0f85f6c358c3eaaae2bae3213a74
parentcdac44e608c3df9a241e0a1b53b3f62af250dbf1 (diff)
downloadrust-ba3b7a7d9c5908633c26145e78166b0d97e518ad.tar.gz
rust-ba3b7a7d9c5908633c26145e78166b0d97e518ad.zip
build-helper: clippy fixes
-rw-r--r--src/build_helper/src/ci.rs2
-rw-r--r--src/build_helper/src/git.rs32
-rw-r--r--src/build_helper/src/metrics.rs2
-rw-r--r--src/build_helper/src/util.rs15
4 files changed, 25 insertions, 26 deletions
diff --git a/src/build_helper/src/ci.rs b/src/build_helper/src/ci.rs
index 9d114c70a67..b5e70eb84cc 100644
--- a/src/build_helper/src/ci.rs
+++ b/src/build_helper/src/ci.rs
@@ -9,7 +9,7 @@ pub enum CiEnv {
 impl CiEnv {
     /// Obtains the current CI environment.
     pub fn current() -> CiEnv {
-        if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") {
+        if std::env::var("GITHUB_ACTIONS").is_ok_and(|e| e == "true") {
             CiEnv::GitHubActions
         } else {
             CiEnv::None
diff --git a/src/build_helper/src/git.rs b/src/build_helper/src/git.rs
index 9d1195aadf8..cbefb836c00 100644
--- a/src/build_helper/src/git.rs
+++ b/src/build_helper/src/git.rs
@@ -13,7 +13,7 @@ pub struct GitConfig<'a> {
 pub fn output_result(cmd: &mut Command) -> Result<String, String> {
     let output = match cmd.stderr(Stdio::inherit()).output() {
         Ok(status) => status,
-        Err(e) => return Err(format!("failed to run command: {:?}: {}", cmd, e)),
+        Err(e) => return Err(format!("failed to run command: {cmd:?}: {e}")),
     };
     if !output.status.success() {
         return Err(format!(
@@ -62,22 +62,22 @@ pub enum PathFreshness {
 /// The function behaves differently in CI and outside CI.
 ///
 /// - Outside CI, we want to find out if `target_paths` were modified in some local commit on
-/// top of the latest upstream commit that is available in local git history.
-/// If not, we try to find the most recent upstream commit (which we assume are commits
-/// made by bors) that modified `target_paths`.
-/// We don't want to simply take the latest master commit to avoid changing the output of
-/// this function frequently after rebasing on the latest master branch even if `target_paths`
-/// were not modified upstream in the meantime. In that case we would be redownloading CI
-/// artifacts unnecessarily.
+///   top of the latest upstream commit that is available in local git history.
+///   If not, we try to find the most recent upstream commit (which we assume are commits
+///   made by bors) that modified `target_paths`.
+///   We don't want to simply take the latest master commit to avoid changing the output of
+///   this function frequently after rebasing on the latest master branch even if `target_paths`
+///   were not modified upstream in the meantime. In that case we would be redownloading CI
+///   artifacts unnecessarily.
 ///
 /// - In CI, we use a shallow clone of depth 2, i.e., we fetch only a single parent commit
-/// (which will be the most recent bors merge commit) and do not have access
-/// to the full git history. Luckily, we only need to distinguish between two situations:
-/// 1) The current PR made modifications to `target_paths`.
-/// In that case, a build is typically necessary.
-/// 2) The current PR did not make modifications to `target_paths`.
-/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
-/// redownloading.
+///   (which will be the most recent bors merge commit) and do not have access
+///   to the full git history. Luckily, we only need to distinguish between two situations:
+///   1) The current PR made modifications to `target_paths`.
+///      In that case, a build is typically necessary.
+///   2) The current PR did not make modifications to `target_paths`.
+///      In that case we simply take the latest upstream commit, because on CI there is no need to avoid
+///      redownloading.
 pub fn check_path_modifications(
     git_dir: &Path,
     config: &GitConfig<'_>,
@@ -232,7 +232,7 @@ pub fn get_closest_upstream_commit(
         "--author-date-order",
         &format!("--author={}", config.git_merge_commit_email),
         "-n1",
-        &base,
+        base,
     ]);
 
     let output = output_result(&mut git)?.trim().to_owned();
diff --git a/src/build_helper/src/metrics.rs b/src/build_helper/src/metrics.rs
index 8b82e62a327..07157e36415 100644
--- a/src/build_helper/src/metrics.rs
+++ b/src/build_helper/src/metrics.rs
@@ -141,7 +141,7 @@ impl BuildStep {
                 } => {
                     let full_name = format!("{parent_name}-{kind}");
                     let children: Vec<_> =
-                        children.into_iter().filter_map(|s| parse(s, &full_name)).collect();
+                        children.iter().filter_map(|s| parse(s, &full_name)).collect();
                     let children_duration = children.iter().map(|c| c.duration).sum::<Duration>();
                     Some(BuildStep {
                         r#type: kind.to_string(),
diff --git a/src/build_helper/src/util.rs b/src/build_helper/src/util.rs
index 80dd6813d13..a8355f774e9 100644
--- a/src/build_helper/src/util.rs
+++ b/src/build_helper/src/util.rs
@@ -18,29 +18,28 @@ macro_rules! exit {
 pub fn detail_exit(code: i32, is_test: bool) -> ! {
     // if in test and code is an error code, panic with status code provided
     if is_test {
-        panic!("status code: {}", code);
+        panic!("status code: {code}");
     } else {
-        // otherwise,exit with provided status code
+        // otherwise, exit with provided status code
         std::process::exit(code);
     }
 }
 
 pub fn fail(s: &str) -> ! {
-    eprintln!("\n\n{}\n\n", s);
+    eprintln!("\n\n{s}\n\n");
     detail_exit(1, cfg!(test));
 }
 
 pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> Result<(), ()> {
     let status = match cmd.status() {
         Ok(status) => status,
-        Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
+        Err(e) => fail(&format!("failed to execute command: {cmd:?}\nerror: {e}")),
     };
     if !status.success() {
         if print_cmd_on_fail {
             println!(
-                "\n\ncommand did not execute successfully: {:?}\n\
-                 expected success, got: {}\n\n",
-                cmd, status
+                "\n\ncommand did not execute successfully: {cmd:?}\n\
+                 expected success, got: {status}\n\n"
             );
         }
         Err(())
@@ -60,7 +59,7 @@ pub fn parse_gitmodules(target_dir: &Path) -> Vec<String> {
     for line in BufReader::new(file).lines().map_while(Result::ok) {
         let line = line.trim();
         if line.starts_with("path") {
-            let actual_path = line.split(' ').last().expect("Couldn't get value of path");
+            let actual_path = line.split(' ').next_back().expect("Couldn't get value of path");
             submodules_paths.push(actual_path.to_owned());
         }
     }