about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2022-02-19 00:48:49 +0100
committerest31 <MTest31@outlook.com>2022-02-19 17:27:43 +0100
commit2ef8af66196f7cc270a0532ea989f2fc6bc6885d (patch)
treee023e65e895d79575848f47b3d00129f9c5a9f0f /compiler/rustc_metadata/src
parentb8c56fa8c30821129b0960180f528d4a1a4f9316 (diff)
downloadrust-2ef8af66196f7cc270a0532ea989f2fc6bc6885d.tar.gz
rust-2ef8af66196f7cc270a0532ea989f2fc6bc6885d.zip
Adopt let else in more places
Diffstat (limited to 'compiler/rustc_metadata/src')
-rw-r--r--compiler/rustc_metadata/src/creader.rs10
-rw-r--r--compiler/rustc_metadata/src/foreign_modules.rs5
-rw-r--r--compiler/rustc_metadata/src/locator.rs13
-rw-r--r--compiler/rustc_metadata/src/native_libs.rs27
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs5
5 files changed, 23 insertions, 37 deletions
diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs
index 36a1798cd6a..7343f1465f6 100644
--- a/compiler/rustc_metadata/src/creader.rs
+++ b/compiler/rustc_metadata/src/creader.rs
@@ -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
diff --git a/compiler/rustc_metadata/src/foreign_modules.rs b/compiler/rustc_metadata/src/foreign_modules.rs
index c70a6914520..c4ee1e19128 100644
--- a/compiler/rustc_metadata/src/foreign_modules.rs
+++ b/compiler/rustc_metadata/src/foreign_modules.rs
@@ -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();
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index 550b22a2a3c..2204b44e3a1 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -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"))
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index 88292a44224..0f10c269a04 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -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 {
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index 7708b5193f4..ce61fd20a7b 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -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)