Adopt let else in more places

This commit is contained in:
est31
2022-02-19 00:48:49 +01:00
parent b8c56fa8c3
commit 2ef8af6619
132 changed files with 539 additions and 881 deletions

View File

@@ -674,9 +674,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
loop {
i += 1;
prog = sess.time("run_linker", || exec_linker(sess, &cmd, out_filename, tmpdir));
let output = match prog {
Ok(ref output) => output,
Err(_) => break,
let Ok(ref output) = prog else {
break;
};
if output.status.success() {
break;
@@ -2025,9 +2024,8 @@ fn add_local_native_libraries(
let search_path = OnceCell::new();
let mut last = (NativeLibKind::Unspecified, None);
for lib in relevant_libs {
let name = match lib.name {
Some(l) => l,
None => continue,
let Some(name) = lib.name else {
continue;
};
// Skip if this library is the same as the last.
@@ -2382,9 +2380,8 @@ fn add_upstream_native_libraries(
let mut last = (NativeLibKind::Unspecified, None);
for &cnum in &codegen_results.crate_info.used_crates {
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
let name = match lib.name {
Some(l) => l,
None => continue,
let Some(name) = lib.name else {
continue;
};
if !relevant_lib(sess, &lib) {
continue;

View File

@@ -79,15 +79,14 @@ fn search_for_metadata<'a>(
bytes: &'a [u8],
section: &str,
) -> Result<&'a [u8], String> {
let file = match object::File::parse(bytes) {
Ok(f) => f,
let Ok(file) = object::File::parse(bytes) else {
// The parse above could fail for odd reasons like corruption, but for
// now we just interpret it as this target doesn't support metadata
// emission in object files so the entire byte slice itself is probably
// a metadata file. Ideally though if necessary we could at least check
// the prefix of bytes to see if it's an actual metadata object and if
// not forward the error along here.
Err(_) => return Ok(bytes),
return Ok(bytes);
};
file.section_by_name(section)
.ok_or_else(|| format!("no `{}` section in '{}'", section, path.display()))?

View File

@@ -448,10 +448,7 @@ fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, S
let mut ret = FxHashMap::default();
for (def_id, lib) in tcx.foreign_modules(cnum).iter() {
let module = def_id_to_native_lib.get(&def_id).and_then(|s| s.wasm_import_module);
let module = match module {
Some(s) => s,
None => continue,
};
let Some(module) = module else { continue };
ret.extend(lib.foreign_items.iter().map(|id| {
assert_eq!(id.krate, cnum);
(*id, module.to_string())