mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 03:57:37 +00:00
rustc_metadata: Cleanup fn encode_info_for_item
This commit is contained in:
parent
d4be8efc62
commit
9dd27b31ba
@ -1523,23 +1523,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) {
|
fn encode_info_for_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
let def_id = item.owner_id.to_def_id();
|
||||||
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
|
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
|
||||||
|
|
||||||
|
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
|
||||||
|
record_array!(this.tables.children[def_id] <- def_ids.iter().map(|&def_id| {
|
||||||
|
assert!(def_id.is_local());
|
||||||
|
def_id.index
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Fn(ref sig, .., body) => {
|
hir::ItemKind::Fn(ref sig, .., body) => {
|
||||||
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
|
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
|
||||||
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
|
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
|
||||||
self.tables.constness.set_some(def_id.index, sig.header.constness);
|
self.tables.constness.set_some(def_id.index, sig.header.constness);
|
||||||
|
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||||
|
self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id));
|
||||||
}
|
}
|
||||||
hir::ItemKind::Macro(ref macro_def, _) => {
|
hir::ItemKind::Macro(ref macro_def, _) => {
|
||||||
self.tables.is_macro_rules.set(def_id.index, macro_def.macro_rules);
|
self.tables.is_macro_rules.set(def_id.index, macro_def.macro_rules);
|
||||||
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
|
record!(self.tables.macro_definition[def_id] <- &*macro_def.body);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Mod(ref m) => {
|
hir::ItemKind::Mod(ref m) => {
|
||||||
return self.encode_info_for_mod(item.owner_id.def_id, m);
|
self.encode_info_for_mod(item.owner_id.def_id, m);
|
||||||
}
|
}
|
||||||
hir::ItemKind::OpaqueTy(ref opaque) => {
|
hir::ItemKind::OpaqueTy(ref opaque) => {
|
||||||
self.encode_explicit_item_bounds(def_id);
|
self.encode_explicit_item_bounds(def_id);
|
||||||
@ -1550,9 +1559,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
||||||
self.tables.impl_defaultness.set_some(def_id.index, *defaultness);
|
self.tables.impl_defaultness.set_some(def_id.index, *defaultness);
|
||||||
self.tables.constness.set_some(def_id.index, *constness);
|
self.tables.constness.set_some(def_id.index, *constness);
|
||||||
|
self.tables.impl_polarity.set_some(def_id.index, self.tcx.impl_polarity(def_id));
|
||||||
|
|
||||||
|
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
|
||||||
|
record!(self.tables.impl_trait_ref[def_id] <- trait_ref);
|
||||||
|
|
||||||
let trait_ref = self.tcx.impl_trait_ref(def_id);
|
|
||||||
if let Some(trait_ref) = trait_ref {
|
|
||||||
let trait_ref = trait_ref.skip_binder();
|
let trait_ref = trait_ref.skip_binder();
|
||||||
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
||||||
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
|
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
|
||||||
@ -1570,21 +1581,27 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let polarity = self.tcx.impl_polarity(def_id);
|
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
|
||||||
self.tables.impl_polarity.set_some(def_id.index, polarity);
|
record_associated_item_def_ids(self, associated_item_def_ids);
|
||||||
|
for &trait_item_def_id in associated_item_def_ids {
|
||||||
|
self.encode_info_for_impl_item(trait_item_def_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(..) => {
|
hir::ItemKind::Trait(..) => {
|
||||||
let trait_def = self.tcx.trait_def(def_id);
|
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
|
||||||
record!(self.tables.trait_def[def_id] <- trait_def);
|
|
||||||
|
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
|
||||||
|
record_associated_item_def_ids(self, associated_item_def_ids);
|
||||||
|
for &item_def_id in associated_item_def_ids {
|
||||||
|
self.encode_info_for_trait_item(item_def_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::TraitAlias(..) => {
|
hir::ItemKind::TraitAlias(..) => {
|
||||||
let trait_def = self.tcx.trait_def(def_id);
|
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
|
||||||
record!(self.tables.trait_def[def_id] <- trait_def);
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {
|
hir::ItemKind::ExternCrate(_)
|
||||||
bug!("cannot encode info for item {:?}", item)
|
| hir::ItemKind::Use(..)
|
||||||
}
|
| hir::ItemKind::Static(..)
|
||||||
hir::ItemKind::Static(..)
|
|
||||||
| hir::ItemKind::Const(..)
|
| hir::ItemKind::Const(..)
|
||||||
| hir::ItemKind::Enum(..)
|
| hir::ItemKind::Enum(..)
|
||||||
| hir::ItemKind::Struct(..)
|
| hir::ItemKind::Struct(..)
|
||||||
@ -1592,49 +1609,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
| hir::ItemKind::ForeignMod { .. }
|
| hir::ItemKind::ForeignMod { .. }
|
||||||
| hir::ItemKind::GlobalAsm(..)
|
| hir::ItemKind::GlobalAsm(..)
|
||||||
| hir::ItemKind::TyAlias(..) => {}
|
| hir::ItemKind::TyAlias(..) => {}
|
||||||
};
|
|
||||||
// FIXME(eddyb) there should be a nicer way to do this.
|
|
||||||
match item.kind {
|
|
||||||
hir::ItemKind::Impl { .. } | hir::ItemKind::Trait(..) => {
|
|
||||||
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
|
|
||||||
record_array!(self.tables.children[def_id] <-
|
|
||||||
associated_item_def_ids.iter().map(|&def_id| {
|
|
||||||
assert!(def_id.is_local());
|
|
||||||
def_id.index
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
if let hir::ItemKind::Fn(..) = item.kind {
|
|
||||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
|
||||||
self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id));
|
|
||||||
}
|
|
||||||
if let hir::ItemKind::Impl { .. } = item.kind {
|
|
||||||
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
|
|
||||||
record!(self.tables.impl_trait_ref[def_id] <- trait_ref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// In some cases, along with the item itself, we also
|
|
||||||
// encode some sub-items. Usually we want some info from the item
|
|
||||||
// so it's easier to do that here then to wait until we would encounter
|
|
||||||
// normally in the visitor walk.
|
|
||||||
match item.kind {
|
|
||||||
hir::ItemKind::Impl { .. } => {
|
|
||||||
for &trait_item_def_id in
|
|
||||||
self.tcx.associated_item_def_ids(item.owner_id.to_def_id()).iter()
|
|
||||||
{
|
|
||||||
self.encode_info_for_impl_item(trait_item_def_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hir::ItemKind::Trait(..) => {
|
|
||||||
for &item_def_id in
|
|
||||||
self.tcx.associated_item_def_ids(item.owner_id.to_def_id()).iter()
|
|
||||||
{
|
|
||||||
self.encode_info_for_trait_item(item_def_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2020,10 +1994,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||||
intravisit::walk_item(self, item);
|
intravisit::walk_item(self, item);
|
||||||
match item.kind {
|
self.encode_info_for_item(item);
|
||||||
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {} // ignore these
|
|
||||||
_ => self.encode_info_for_item(item.owner_id.to_def_id(), item),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) {
|
fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem<'tcx>) {
|
||||||
intravisit::walk_foreign_item(self, ni);
|
intravisit::walk_foreign_item(self, ni);
|
||||||
|
Loading…
Reference in New Issue
Block a user