about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLingMan <LingMan@users.noreply.github.com>2021-01-03 09:19:52 +0100
committerLingMan <LingMan@users.noreply.github.com>2021-01-03 10:07:22 +0100
commitaf7134e7de793ea3bba30bc350daef76ea9de755 (patch)
tree3bc2a8de7f4b08dfc9aba4f90d818591f1cadbfb
parent18d855b8f6358d34dbee033faccc82b8c849a4b3 (diff)
downloadrust-af7134e7de793ea3bba30bc350daef76ea9de755.tar.gz
rust-af7134e7de793ea3bba30bc350daef76ea9de755.zip
Move variable into the only branch where it is relevant
At the `if` branch `filter` (the `let` binding) is `None` iff `filter` (the parameter) was `None`.
We can branch on the parameter, move the binding into the `if`, and the complexity of handling
`Option<Option<_>` largely dissolves.
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index 43f7b2a9928..4aaacdc593f 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1345,15 +1345,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
             return &[];
         }
 
-        // Do a reverse lookup beforehand to avoid touching the crate_num
-        // hash map in the loop below.
-        let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
-            Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
-            Some(None) => return &[],
-            None => None,
-        };
+        if let Some(def_id) = filter {
+            // Do a reverse lookup beforehand to avoid touching the crate_num
+            // hash map in the loop below.
+            let filter = match self.reverse_translate_def_id(def_id) {
+                Some(def_id) => (def_id.krate.as_u32(), def_id.index),
+                None => return &[],
+            };
 
-        if let Some(filter) = filter {
             if let Some(impls) = self.trait_impls.get(&filter) {
                 tcx.arena.alloc_from_iter(
                     impls.decode(self).map(|(idx, simplified_self_ty)| {