Adopt let else in more places
This commit is contained in:
parent
b8c56fa8c3
commit
2ef8af6619
132 changed files with 539 additions and 881 deletions
|
@ -475,9 +475,8 @@ impl<'a> CrateLoader<'a> {
|
|||
locator.triple = TargetTriple::from_triple(config::host_triple());
|
||||
locator.filesearch = self.sess.host_filesearch(path_kind);
|
||||
|
||||
let host_result = match self.load(locator)? {
|
||||
Some(host_result) => host_result,
|
||||
None => return Ok(None),
|
||||
let Some(host_result) = self.load(locator)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
Ok(Some(if self.sess.opts.debugging_opts.dual_proc_macros {
|
||||
|
@ -574,9 +573,8 @@ impl<'a> CrateLoader<'a> {
|
|||
}
|
||||
|
||||
fn load(&self, locator: &mut CrateLocator<'_>) -> Result<Option<LoadResult>, CrateError> {
|
||||
let library = match locator.maybe_load_library_crate()? {
|
||||
Some(library) => library,
|
||||
None => return Ok(None),
|
||||
let Some(library) = locator.maybe_load_library_crate()? else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
// In the case that we're loading a crate, but not matching
|
||||
|
|
|
@ -15,9 +15,8 @@ struct Collector {
|
|||
|
||||
impl<'tcx> ItemLikeVisitor<'tcx> for Collector {
|
||||
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
|
||||
let items = match it.kind {
|
||||
hir::ItemKind::ForeignMod { items, .. } => items,
|
||||
_ => return,
|
||||
let hir::ItemKind::ForeignMod { items, .. } = it.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
|
||||
|
|
|
@ -690,14 +690,11 @@ impl<'a> CrateLocator<'a> {
|
|||
loc.original().clone(),
|
||||
));
|
||||
}
|
||||
let file = match loc.original().file_name().and_then(|s| s.to_str()) {
|
||||
Some(file) => file,
|
||||
None => {
|
||||
return Err(CrateError::ExternLocationNotFile(
|
||||
self.crate_name,
|
||||
loc.original().clone(),
|
||||
));
|
||||
}
|
||||
let Some(file) = loc.original().file_name().and_then(|s| s.to_str()) else {
|
||||
return Err(CrateError::ExternLocationNotFile(
|
||||
self.crate_name,
|
||||
loc.original().clone(),
|
||||
));
|
||||
};
|
||||
|
||||
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
|
||||
|
|
|
@ -33,9 +33,8 @@ struct Collector<'tcx> {
|
|||
|
||||
impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
||||
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
|
||||
let (abi, foreign_mod_items) = match it.kind {
|
||||
hir::ItemKind::ForeignMod { abi, items } => (abi, items),
|
||||
_ => return,
|
||||
let hir::ItemKind::ForeignMod { abi, items: foreign_mod_items } = it.kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
if abi == Abi::Rust || abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
|
||||
|
@ -45,9 +44,8 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
|||
// Process all of the #[link(..)]-style arguments
|
||||
let sess = &self.tcx.sess;
|
||||
for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| a.has_name(sym::link)) {
|
||||
let items = match m.meta_item_list() {
|
||||
Some(item) => item,
|
||||
None => continue,
|
||||
let Some(items) = m.meta_item_list() else {
|
||||
continue;
|
||||
};
|
||||
let mut lib = NativeLib {
|
||||
name: None,
|
||||
|
@ -63,9 +61,8 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
|||
for item in items.iter() {
|
||||
if item.has_name(sym::kind) {
|
||||
kind_specified = true;
|
||||
let kind = match item.value_str() {
|
||||
Some(name) => name,
|
||||
None => continue, // skip like historical compilers
|
||||
let Some(kind) = item.value_str() else {
|
||||
continue; // skip like historical compilers
|
||||
};
|
||||
lib.kind = match kind.as_str() {
|
||||
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
|
||||
|
@ -101,9 +98,8 @@ impl<'tcx> ItemLikeVisitor<'tcx> for Collector<'tcx> {
|
|||
} else if item.has_name(sym::name) {
|
||||
lib.name = item.value_str();
|
||||
} else if item.has_name(sym::cfg) {
|
||||
let cfg = match item.meta_item_list() {
|
||||
Some(list) => list,
|
||||
None => continue, // skip like historical compilers
|
||||
let Some(cfg) = item.meta_item_list() else {
|
||||
continue; // skip like historical compilers
|
||||
};
|
||||
if cfg.is_empty() {
|
||||
sess.span_err(item.span(), "`cfg()` must have an argument");
|
||||
|
@ -262,11 +258,8 @@ impl Collector<'_> {
|
|||
}
|
||||
// this just unwraps lib.name; we already established that it isn't empty above.
|
||||
if let (NativeLibKind::RawDylib, Some(lib_name)) = (lib.kind, lib.name) {
|
||||
let span = match span {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
bug!("raw-dylib libraries are not supported on the command line");
|
||||
}
|
||||
let Some(span) = span else {
|
||||
bug!("raw-dylib libraries are not supported on the command line");
|
||||
};
|
||||
|
||||
if !self.tcx.sess.target.options.is_like_windows {
|
||||
|
|
|
@ -249,9 +249,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
|||
.iter()
|
||||
.filter(|lib| native_libs::relevant_lib(&tcx.sess, lib))
|
||||
.find(|lib| {
|
||||
let fm_id = match lib.foreign_module {
|
||||
Some(id) => id,
|
||||
None => return false,
|
||||
let Some(fm_id) = lib.foreign_module else {
|
||||
return false;
|
||||
};
|
||||
let map = tcx.foreign_modules(id.krate);
|
||||
map.get(&fm_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue