Skip to content

Commit ba3b7a7

Browse files
committed
build-helper: clippy fixes
1 parent cdac44e commit ba3b7a7

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

src/build_helper/src/ci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum CiEnv {
99
impl CiEnv {
1010
/// Obtains the current CI environment.
1111
pub fn current() -> CiEnv {
12-
if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") {
12+
if std::env::var("GITHUB_ACTIONS").is_ok_and(|e| e == "true") {
1313
CiEnv::GitHubActions
1414
} else {
1515
CiEnv::None

src/build_helper/src/git.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct GitConfig<'a> {
1313
pub fn output_result(cmd: &mut Command) -> Result<String, String> {
1414
let output = match cmd.stderr(Stdio::inherit()).output() {
1515
Ok(status) => status,
16-
Err(e) => return Err(format!("failed to run command: {:?}: {}", cmd, e)),
16+
Err(e) => return Err(format!("failed to run command: {cmd:?}: {e}")),
1717
};
1818
if !output.status.success() {
1919
return Err(format!(
@@ -62,22 +62,22 @@ pub enum PathFreshness {
6262
/// The function behaves differently in CI and outside CI.
6363
///
6464
/// - Outside CI, we want to find out if `target_paths` were modified in some local commit on
65-
/// top of the latest upstream commit that is available in local git history.
66-
/// If not, we try to find the most recent upstream commit (which we assume are commits
67-
/// made by bors) that modified `target_paths`.
68-
/// We don't want to simply take the latest master commit to avoid changing the output of
69-
/// this function frequently after rebasing on the latest master branch even if `target_paths`
70-
/// were not modified upstream in the meantime. In that case we would be redownloading CI
71-
/// artifacts unnecessarily.
65+
/// top of the latest upstream commit that is available in local git history.
66+
/// If not, we try to find the most recent upstream commit (which we assume are commits
67+
/// made by bors) that modified `target_paths`.
68+
/// We don't want to simply take the latest master commit to avoid changing the output of
69+
/// this function frequently after rebasing on the latest master branch even if `target_paths`
70+
/// were not modified upstream in the meantime. In that case we would be redownloading CI
71+
/// artifacts unnecessarily.
7272
///
7373
/// - In CI, we use a shallow clone of depth 2, i.e., we fetch only a single parent commit
74-
/// (which will be the most recent bors merge commit) and do not have access
75-
/// to the full git history. Luckily, we only need to distinguish between two situations:
76-
/// 1) The current PR made modifications to `target_paths`.
77-
/// In that case, a build is typically necessary.
78-
/// 2) The current PR did not make modifications to `target_paths`.
79-
/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
80-
/// redownloading.
74+
/// (which will be the most recent bors merge commit) and do not have access
75+
/// to the full git history. Luckily, we only need to distinguish between two situations:
76+
/// 1) The current PR made modifications to `target_paths`.
77+
/// In that case, a build is typically necessary.
78+
/// 2) The current PR did not make modifications to `target_paths`.
79+
/// In that case we simply take the latest upstream commit, because on CI there is no need to avoid
80+
/// redownloading.
8181
pub fn check_path_modifications(
8282
git_dir: &Path,
8383
config: &GitConfig<'_>,
@@ -232,7 +232,7 @@ pub fn get_closest_upstream_commit(
232232
"--author-date-order",
233233
&format!("--author={}", config.git_merge_commit_email),
234234
"-n1",
235-
&base,
235+
base,
236236
]);
237237

238238
let output = output_result(&mut git)?.trim().to_owned();

src/build_helper/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl BuildStep {
141141
} => {
142142
let full_name = format!("{parent_name}-{kind}");
143143
let children: Vec<_> =
144-
children.into_iter().filter_map(|s| parse(s, &full_name)).collect();
144+
children.iter().filter_map(|s| parse(s, &full_name)).collect();
145145
let children_duration = children.iter().map(|c| c.duration).sum::<Duration>();
146146
Some(BuildStep {
147147
r#type: kind.to_string(),

src/build_helper/src/util.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,28 @@ macro_rules! exit {
1818
pub fn detail_exit(code: i32, is_test: bool) -> ! {
1919
// if in test and code is an error code, panic with status code provided
2020
if is_test {
21-
panic!("status code: {}", code);
21+
panic!("status code: {code}");
2222
} else {
23-
// otherwise,exit with provided status code
23+
// otherwise, exit with provided status code
2424
std::process::exit(code);
2525
}
2626
}
2727

2828
pub fn fail(s: &str) -> ! {
29-
eprintln!("\n\n{}\n\n", s);
29+
eprintln!("\n\n{s}\n\n");
3030
detail_exit(1, cfg!(test));
3131
}
3232

3333
pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> Result<(), ()> {
3434
let status = match cmd.status() {
3535
Ok(status) => status,
36-
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
36+
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nerror: {e}")),
3737
};
3838
if !status.success() {
3939
if print_cmd_on_fail {
4040
println!(
41-
"\n\ncommand did not execute successfully: {:?}\n\
42-
expected success, got: {}\n\n",
43-
cmd, status
41+
"\n\ncommand did not execute successfully: {cmd:?}\n\
42+
expected success, got: {status}\n\n"
4443
);
4544
}
4645
Err(())
@@ -60,7 +59,7 @@ pub fn parse_gitmodules(target_dir: &Path) -> Vec<String> {
6059
for line in BufReader::new(file).lines().map_while(Result::ok) {
6160
let line = line.trim();
6261
if line.starts_with("path") {
63-
let actual_path = line.split(' ').last().expect("Couldn't get value of path");
62+
let actual_path = line.split(' ').next_back().expect("Couldn't get value of path");
6463
submodules_paths.push(actual_path.to_owned());
6564
}
6665
}

0 commit comments

Comments
 (0)