Skip to content

Commit 30b29ab

Browse files
committed
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`.
1 parent cca64e7 commit 30b29ab

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
127127
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
128128
})
129129
}
130-
optimized_mir => {
131-
let mir = cdata.maybe_get_optimized_mir(tcx, def_id.index).unwrap_or_else(|| {
132-
bug!("get_optimized_mir: missing MIR for `{:?}`", def_id)
133-
});
134-
135-
let mir = tcx.arena.alloc(mir);
136-
137-
mir
138-
}
139-
promoted_mir => {
140-
let promoted = cdata.maybe_get_promoted_mir(tcx, def_id.index).unwrap_or_else(|| {
141-
bug!("get_promoted_mir: missing promoted MIR for `{:?}`", def_id)
142-
});
143-
144-
let promoted = tcx.arena.alloc(promoted);
145-
146-
promoted
147-
}
130+
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
131+
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
148132
mir_const_qualif => {
149133
(cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
150134
}

src/librustc_metadata/decoder.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -917,22 +917,32 @@ impl<'a, 'tcx> CrateMetadata {
917917
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
918918
}
919919

920-
pub fn maybe_get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Option<Body<'tcx>> {
921-
match self.is_proc_macro(id) {
922-
true => None,
923-
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
924-
}
920+
pub fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
921+
let mir =
922+
match self.is_proc_macro(id) {
923+
true => None,
924+
false => self.entry(id).mir.map(|mir| mir.decode((self, tcx))),
925+
};
926+
927+
mir.unwrap_or_else(|| {
928+
bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
929+
})
925930
}
926931

927-
pub fn maybe_get_promoted_mir(
932+
pub fn get_promoted_mir(
928933
&self,
929934
tcx: TyCtxt<'tcx>,
930935
id: DefIndex,
931-
) -> Option<IndexVec<Promoted, Body<'tcx>>> {
932-
match self.is_proc_macro(id) {
933-
true => None,
934-
false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)),)
935-
}
936+
) -> IndexVec<Promoted, Body<'tcx>> {
937+
let promoted =
938+
match self.is_proc_macro(id) {
939+
true => None,
940+
false => self.entry(id).promoted_mir.map(|promoted| promoted.decode((self, tcx)))
941+
};
942+
943+
promoted.unwrap_or_else(|| {
944+
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
945+
})
936946
}
937947

938948
pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {

0 commit comments

Comments
 (0)