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`.
This commit is contained in:
Wesley Wiser 2019-08-26 21:58:16 -04:00
parent cca64e7339
commit 30b29ab0f7
2 changed files with 23 additions and 29 deletions

View file

@ -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)))
}

View file

@ -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 {