diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 10b165c90662..4d2f9f58226d 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -450,11 +450,19 @@ impl<'a, 'tcx> CrateMetadata { pub fn is_proc_macro_crate(&self) -> bool { self.root.proc_macro_decls_static.is_some() } + fn is_proc_macro(&self, id: DefIndex) -> bool { self.is_proc_macro_crate() && self.root.proc_macro_data.unwrap().decode(self).find(|x| *x == id).is_some() } + fn entry_unless_proc_macro(&self, id: DefIndex) -> Option> { + match self.is_proc_macro(id) { + true => None, + false => Some(self.entry(id)), + } + } + fn maybe_entry(&self, item_id: DefIndex) -> Option>> { self.root.entries_index.lookup(self.blob.raw_bytes(), item_id) } @@ -704,10 +712,8 @@ impl<'a, 'tcx> CrateMetadata { } pub fn get_deprecation(&self, id: DefIndex) -> Option { - match self.is_proc_macro(id) { - true => None, - false => self.entry(id).deprecation.map(|depr| depr.decode(self)), - } + self.entry_unless_proc_macro(id) + .and_then(|entry| entry.deprecation.map(|depr| depr.decode(self))) } pub fn get_visibility(&self, id: DefIndex) -> ty::Visibility { @@ -918,15 +924,11 @@ impl<'a, 'tcx> CrateMetadata { } 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)) - }) + self.entry_unless_proc_macro(id) + .and_then(|entry| entry.mir.map(|mir| mir.decode((self, tcx)))) + .unwrap_or_else(|| { + bug!("get_optimized_mir: missing MIR for `{:?}", self.local_def_id(id)) + }) } pub fn get_promoted_mir( @@ -934,15 +936,11 @@ impl<'a, 'tcx> CrateMetadata { tcx: TyCtxt<'tcx>, id: DefIndex, ) -> IndexVec> { - 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)) - }) + self.entry_unless_proc_macro(id) + .and_then(|entry| entry.promoted_mir.map(|promoted| promoted.decode((self, tcx)))) + .unwrap_or_else(|| { + bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id)) + }) } pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {