From 675059a9ebab0b00b25542dd955f8efa9aed5dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 3 Jan 2021 12:47:38 +0100 Subject: [PATCH 1/3] Clean up convoluted macros_only logic --- compiler/rustc_metadata/src/rmeta/decoder.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 43f7b2a9928..1c80523c9c6 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1055,19 +1055,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { // Iterate over all children. let macros_only = self.dep_kind.lock().macros_only(); - let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty); - for child_index in children.decode((self, sess)) { - if macros_only { - continue; - } + if !macros_only { + let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty); - // Get the item. - if let Some(child_kind) = self.maybe_kind(child_index) { - match child_kind { - EntryKind::MacroDef(..) => {} - _ if macros_only => continue, - _ => {} - } + for child_index in children.decode((self, sess)) { + // Get the item. + let child_kind = match self.maybe_kind(child_index) { + Some(child_kind) => child_kind, + None => continue, + }; // Hand off the item to the callback. match child_kind { From 250fb72d1b39b013d661544428bd5db315573da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 3 Jan 2021 12:49:53 +0100 Subject: [PATCH 2/3] No need to collect result of get_item_attrs --- compiler/rustc_metadata/src/rmeta/decoder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 1c80523c9c6..90e72ba2ac2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1133,9 +1133,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { // within the crate. We only need this for fictive constructors, // for other constructors correct visibilities // were already encoded in metadata. - let attrs: Vec<_> = - self.get_item_attrs(def_id.index, sess).collect(); - if sess.contains_name(&attrs, sym::non_exhaustive) { + let mut attrs = self.get_item_attrs(def_id.index, sess); + if attrs.any(|item| item.has_name(sym::non_exhaustive)) { let crate_def_id = self.local_def_id(CRATE_DEF_INDEX); vis = ty::Visibility::Restricted(crate_def_id); } From 4d3227fe1c14c089afb6d2bfa266a78336bf4fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 3 Jan 2021 12:50:29 +0100 Subject: [PATCH 3/3] Move variable into condition where it's used --- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 90e72ba2ac2..a4bb5f8dc95 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1098,8 +1098,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } 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() { + let span = self.get_span(child_index, sess); let kind = self.def_kind(child_index); let ident = self.item_ident(child_index, sess); let vis = self.get_visibility(child_index);