Skip to content

Commit 539c435

Browse files
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
2 parents ff1f21a + 4d3227f commit 539c435

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -1055,19 +1055,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10551055

10561056
// Iterate over all children.
10571057
let macros_only = self.dep_kind.lock().macros_only();
1058-
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
1059-
for child_index in children.decode((self, sess)) {
1060-
if macros_only {
1061-
continue;
1062-
}
1063-
1064-
// Get the item.
1065-
if let Some(child_kind) = self.maybe_kind(child_index) {
1066-
match child_kind {
1067-
EntryKind::MacroDef(..) => {}
1068-
_ if macros_only => continue,
1069-
_ => {}
1070-
}
1058+
if !macros_only {
1059+
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
1060+
1061+
for child_index in children.decode((self, sess)) {
1062+
// Get the item.
1063+
let child_kind = match self.maybe_kind(child_index) {
1064+
Some(child_kind) => child_kind,
1065+
None => continue,
1066+
};
10711067

10721068
// Hand off the item to the callback.
10731069
match child_kind {
@@ -1102,8 +1098,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11021098
}
11031099

11041100
let def_key = self.def_key(child_index);
1105-
let span = self.get_span(child_index, sess);
11061101
if def_key.disambiguated_data.data.get_opt_name().is_some() {
1102+
let span = self.get_span(child_index, sess);
11071103
let kind = self.def_kind(child_index);
11081104
let ident = self.item_ident(child_index, sess);
11091105
let vis = self.get_visibility(child_index);
@@ -1137,9 +1133,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11371133
// within the crate. We only need this for fictive constructors,
11381134
// for other constructors correct visibilities
11391135
// were already encoded in metadata.
1140-
let attrs: Vec<_> =
1141-
self.get_item_attrs(def_id.index, sess).collect();
1142-
if sess.contains_name(&attrs, sym::non_exhaustive) {
1136+
let mut attrs = self.get_item_attrs(def_id.index, sess);
1137+
if attrs.any(|item| item.has_name(sym::non_exhaustive)) {
11431138
let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
11441139
vis = ty::Visibility::Restricted(crate_def_id);
11451140
}

0 commit comments

Comments
 (0)