Skip to content

Commit fe2fc94

Browse files
committed
bootstrap
1 parent 9bd3cf7 commit fe2fc94

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

src/bootstrap/src/utils/helpers.rs

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ pub fn submodule_path_of(builder: &Builder<'_>, path: &str) -> Option<String> {
6868
}
6969

7070
fn is_aix_shared_archive(path: &Path) -> bool {
71-
let file = match fs::File::open(path) {
72-
Ok(file) => file,
73-
Err(_) => return false,
71+
let Ok(file) = fs::File::open(path) else {
72+
return false;
7473
};
7574
let reader = object::ReadCache::new(file);
76-
let archive = match ArchiveFile::parse(&reader) {
77-
Ok(result) => result,
78-
Err(_) => return false,
75+
let Ok(archive) = ArchiveFile::parse(&reader) else {
76+
return false;
7977
};
8078

8179
archive
@@ -99,10 +97,7 @@ pub fn libdir(target: TargetSelection) -> &'static str {
9997
/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.
10098
/// If the dylib_path_var is already set for this cmd, the old value will be overwritten!
10199
pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut BootstrapCommand) {
102-
let mut list = dylib_path();
103-
for path in path {
104-
list.insert(0, path);
105-
}
100+
let list = path.into_iter().rev().chain(dylib_path());
106101
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
107102
}
108103

@@ -156,7 +151,7 @@ pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<(
156151
}
157152

158153
pub fn forcing_clang_based_tests() -> bool {
159-
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
154+
env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS").is_some_and(|var| {
160155
match &var.to_string_lossy().to_lowercase()[..] {
161156
"1" | "yes" | "on" => true,
162157
"0" | "no" | "off" => false,
@@ -168,9 +163,7 @@ pub fn forcing_clang_based_tests() -> bool {
168163
)
169164
}
170165
}
171-
} else {
172-
false
173-
}
166+
})
174167
}
175168

176169
pub fn use_host_linker(target: TargetSelection) -> bool {
@@ -206,10 +199,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
206199
builder: &Builder<'_>,
207200
) -> Option<&'a str> {
208201
let suite_path = suite_path.as_ref();
209-
let path = match path.strip_prefix(".") {
210-
Ok(p) => p,
211-
Err(_) => path,
212-
};
202+
let path = path.strip_prefix(".").unwrap_or(path);
213203
if !path.starts_with(suite_path) {
214204
return None;
215205
}
@@ -227,20 +217,15 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
227217
// Therefore, we need to filter these out, as only the first --test-args
228218
// flag is respected, so providing an empty --test-args conflicts with
229219
// any following it.
230-
match path.strip_prefix(suite_path).ok().and_then(|p| p.to_str()) {
231-
Some(s) if !s.is_empty() => Some(s),
232-
_ => None,
233-
}
220+
path.strip_prefix(suite_path).ok().and_then(|p| p.to_str()).filter(|s| !s.is_empty())
234221
}
235222

236223
// FIXME: get rid of this function
237224
pub fn check_run(cmd: &mut BootstrapCommand, print_cmd_on_fail: bool) -> bool {
238-
let status = match cmd.as_command_mut().status() {
239-
Ok(status) => status,
240-
Err(e) => {
241-
println!("failed to execute command: {cmd:?}\nERROR: {e}");
242-
return false;
243-
}
225+
let Ok(status) = cmd.as_command_mut().status().inspect_err(|e| {
226+
println!("failed to execute command: {cmd:?}\nERROR: {e}");
227+
}) else {
228+
return false;
244229
};
245230
if !status.success() && print_cmd_on_fail {
246231
println!(
@@ -512,16 +497,15 @@ where
512497
pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
513498
// Creating a string of the values by concatenating each value:
514499
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
515-
let next = match values {
516-
Some(values) => {
500+
let next = values
501+
.map(|values| {
517502
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
518503

519504
tmp.insert_str(1, "values(");
520505
tmp.push(')');
521506
tmp
522-
}
523-
None => "".to_string(),
524-
};
507+
})
508+
.unwrap_or_default();
525509
format!("--check-cfg=cfg({name}{next})")
526510
}
527511

0 commit comments

Comments
 (0)