Extract Decoder::entry_unless_proc_macro()
This commit is contained in:
parent
30b29ab0f7
commit
009cce88eb
1 changed files with 20 additions and 22 deletions
|
@ -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<Entry<'tcx>> {
|
||||
match self.is_proc_macro(id) {
|
||||
true => None,
|
||||
false => Some(self.entry(id)),
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
|
||||
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<attr::Deprecation> {
|
||||
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<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))
|
||||
})
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue