Skip to content

Commit 009cce8

Browse files
committed
Extract Decoder::entry_unless_proc_macro()
1 parent 30b29ab commit 009cce8

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/librustc_metadata/decoder.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata {
450450
pub fn is_proc_macro_crate(&self) -> bool {
451451
self.root.proc_macro_decls_static.is_some()
452452
}
453+
453454
fn is_proc_macro(&self, id: DefIndex) -> bool {
454455
self.is_proc_macro_crate() &&
455456
self.root.proc_macro_data.unwrap().decode(self).find(|x| *x == id).is_some()
456457
}
457458

459+
fn entry_unless_proc_macro(&self, id: DefIndex) -> Option<Entry<'tcx>> {
460+
match self.is_proc_macro(id) {
461+
true => None,
462+
false => Some(self.entry(id)),
463+
}
464+
}
465+
458466
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
459467
self.root.entries_index.lookup(self.blob.raw_bytes(), item_id)
460468
}
@@ -704,10 +712,8 @@ impl<'a, 'tcx> CrateMetadata {
704712
}
705713

706714
pub fn get_deprecation(&self, id: DefIndex) -> Option<attr::Deprecation> {
707-
match self.is_proc_macro(id) {
708-
true => None,
709-
false => self.entry(id).deprecation.map(|depr| depr.decode(self)),
710-
}
715+
self.entry_unless_proc_macro(id)
716+
.and_then(|entry| entry.deprecation.map(|depr| depr.decode(self)))
711717
}
712718

713719
pub fn get_visibility(&self, id: DefIndex) -> ty::Visibility {
@@ -918,31 +924,23 @@ impl<'a, 'tcx> CrateMetadata {
918924
}
919925

920926
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-
})
927+
self.entry_unless_proc_macro(id)
928+
.and_then(|entry| entry.mir.map(|mir| mir.decode((self, tcx))))
929+
.unwrap_or_else(|| {
930+
bug!("get_optimized_mir: missing MIR for `{:?}", self.local_def_id(id))
931+
})
930932
}
931933

932934
pub fn get_promoted_mir(
933935
&self,
934936
tcx: TyCtxt<'tcx>,
935937
id: DefIndex,
936938
) -> 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-
})
939+
self.entry_unless_proc_macro(id)
940+
.and_then(|entry| entry.promoted_mir.map(|promoted| promoted.decode((self, tcx))))
941+
.unwrap_or_else(|| {
942+
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
943+
})
946944
}
947945

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

0 commit comments

Comments
 (0)