about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-08-26 21:58:16 -0400
committerWesley Wiser <wwiser@gmail.com>2019-08-28 07:00:27 -0400
commit30b29ab0f7c54a2ca74de5117395371101fa9518 (patch)
tree26a33907ddc7621451273a3de87a1c3c8402c112
parentcca64e73399c02b2f964e3b34f969e826d061eed (diff)
downloadrust-30b29ab0f7c54a2ca74de5117395371101fa9518.tar.gz
rust-30b29ab0f7c54a2ca74de5117395371101fa9518.zip
Simplify `maybe_get_optimized_mir` and `maybe_get_promoted_mir`
Since both functions are always unwrapped, don't wrap the return value
in an `Option`.
-rw-r--r--src/librustc_metadata/cstore_impl.rs20
-rw-r--r--src/librustc_metadata/decoder.rs32
2 files changed, 23 insertions, 29 deletions
diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs
index 7aeeef00ea9..81e0cd7a4c4 100644
--- a/src/librustc_metadata/cstore_impl.rs
+++ b/src/librustc_metadata/cstore_impl.rs
@@ -127,24 +127,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
             bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
         })
     }
-    optimized_mir => {
-        let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
-            bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
-        });
-
-        let mir = tcx.arena.alloc(mir);
-
-        mir
-    }
-    promoted_mir => {
-        let promoted = cdata.maybe_get_promoted_mir(tcx, def_id.index).unwrap_or_else(|| {
-            bug!("get_promoted_mir: missing promoted MIR for `{:?}`", def_id)
-        });
-
-        let promoted = tcx.arena.alloc(promoted);
-
-        promoted
-    }
+    optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
+    promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
     mir_const_qualif => {
         (cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
     }
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 5b9cb966af2..10b165c9066 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -917,22 +917,32 @@ impl<'a, 'tcx> CrateMetadata {
         self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
     }
 
-    pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Option<Body<'tcx>> {
-        match self.is_proc_macro(id) {
-            true => None,
-            false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
-        }
+    pub fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
+        let mir =
+            match self.is_proc_macro(id) {
+                true => None,
+                false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
+            };
+
+        mir.unwrap_or_else(|| {
+            bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
+        })
     }
 
-    pub fn maybe_get_promoted_mir(
+    pub fn get_promoted_mir(
         &self,
         tcx: TyCtxt<'tcx>,
         id: DefIndex,
-    ) -> Option<IndexVec<Promoted, Body<'tcx>>> {
-        match self.is_proc_macro(id) {
-            true => None,
-            false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)),)
-        }
+    ) -> IndexVec<Promoted, Body<'tcx>> {
+        let promoted =
+            match self.is_proc_macro(id) {
+                true => None,
+                false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)))
+            };
+
+        promoted.unwrap_or_else(|| {
+            bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
+        })
     }
 
     pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {