Rollup merge of #80646 - bugadani:meta, r=petrochenkov

Clean up in `each_child_of_item`

This PR hopes to eliminate some of the surprising elements I encountered while reading the function.
- `macros_only` is checked against inside the loop body, but if it is `true`, the loop is skipped anyway
- only query `span` when relevant
- no need to allocate attribute vector
This commit is contained in:
Guillaume Gomez 2021-01-03 17:09:13 +01:00 committed by GitHub
commit 539c435b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1055,19 +1055,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
// Iterate over all children. // Iterate over all children.
let macros_only = self.dep_kind.lock().macros_only(); let macros_only = self.dep_kind.lock().macros_only();
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty); if !macros_only {
for child_index in children.decode((self, sess)) { let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
if macros_only {
continue;
}
// Get the item. for child_index in children.decode((self, sess)) {
if let Some(child_kind) = self.maybe_kind(child_index) { // Get the item.
match child_kind { let child_kind = match self.maybe_kind(child_index) {
EntryKind::MacroDef(..) => {} Some(child_kind) => child_kind,
_ if macros_only => continue, None => continue,
_ => {} };
}
// Hand off the item to the callback. // Hand off the item to the callback.
match child_kind { match child_kind {
@ -1102,8 +1098,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
let def_key = self.def_key(child_index); let def_key = self.def_key(child_index);
let span = self.get_span(child_index, sess);
if def_key.disambiguated_data.data.get_opt_name().is_some() { if def_key.disambiguated_data.data.get_opt_name().is_some() {
let span = self.get_span(child_index, sess);
let kind = self.def_kind(child_index); let kind = self.def_kind(child_index);
let ident = self.item_ident(child_index, sess); let ident = self.item_ident(child_index, sess);
let vis = self.get_visibility(child_index); let vis = self.get_visibility(child_index);
@ -1137,9 +1133,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
// within the crate. We only need this for fictive constructors, // within the crate. We only need this for fictive constructors,
// for other constructors correct visibilities // for other constructors correct visibilities
// were already encoded in metadata. // were already encoded in metadata.
let attrs: Vec<_> = let mut attrs = self.get_item_attrs(def_id.index, sess);
self.get_item_attrs(def_id.index, sess).collect(); if attrs.any(|item| item.has_name(sym::non_exhaustive)) {
if sess.contains_name(&attrs, sym::non_exhaustive) {
let crate_def_id = self.local_def_id(CRATE_DEF_INDEX); let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
vis = ty::Visibility::Restricted(crate_def_id); vis = ty::Visibility::Restricted(crate_def_id);
} }