diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 746c3b6af12f..a1df1a63fc58 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -784,6 +784,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } }; + let attrs: Vec<_> = self.get_item_attrs(id, sess).collect(); SyntaxExtension::new( sess, kind, @@ -791,7 +792,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { helper_attrs, self.root.edition, Symbol::intern(name), - &self.get_item_attrs(id, sess), + &attrs, ) } @@ -1157,7 +1158,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 = self.get_item_attrs(def_id.index, sess); + let attrs: Vec<_> = + self.get_item_attrs(def_id.index, sess).collect(); if sess.contains_name(&attrs, sym::non_exhaustive) { let crate_def_id = self.local_def_id(CRATE_DEF_INDEX); vis = ty::Visibility::Restricted(crate_def_id); @@ -1283,8 +1285,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } } - fn get_item_variances(&self, id: DefIndex) -> Vec { - self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self).collect() + fn get_item_variances(&'a self, id: DefIndex) -> impl Iterator + 'a { + self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self) } fn get_ctor_kind(&self, node_id: DefIndex) -> CtorKind { @@ -1308,7 +1310,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } } - fn get_item_attrs(&self, node_id: DefIndex, sess: &Session) -> Vec { + fn get_item_attrs( + &'a self, + node_id: DefIndex, + sess: &'a Session, + ) -> impl Iterator + 'a { // The attributes for a tuple struct/variant are attached to the definition, not the ctor; // we assume that someone passing in a tuple struct ctor is actually wanting to // look at the definition @@ -1325,7 +1331,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { .get(self, item_id) .unwrap_or_else(Lazy::empty) .decode((self, sess)) - .collect::>() } fn get_struct_field_names(&self, id: DefIndex, sess: &Session) -> Vec> { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index ddd85ab7aaa8..d24e1f5d4dd0 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -138,7 +138,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, cdata.get_deprecation(def_id.index).map(DeprecationEntry::external) } item_attrs => { tcx.arena.alloc_from_iter( - cdata.get_item_attrs(def_id.index, tcx.sess).into_iter() + cdata.get_item_attrs(def_id.index, tcx.sess) ) } fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) } rendered_const => { cdata.get_rendered_const(def_id.index) } @@ -415,11 +415,7 @@ impl CStore { let span = data.get_span(id.index, sess); - // Mark the attrs as used - let attrs = data.get_item_attrs(id.index, sess); - for attr in attrs.iter() { - sess.mark_attr_used(attr); - } + let attrs: Vec<_> = data.get_item_attrs(id.index, sess).collect(); let ident = data.item_ident(id.index, sess); @@ -428,7 +424,7 @@ impl CStore { ident, id: ast::DUMMY_NODE_ID, span, - attrs: attrs.to_vec(), + attrs, kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)), vis: ast::Visibility { span: span.shrink_to_lo(),