Skip to content

Commit 660d8a6

Browse files
committed
Eliminate some temporary vectors & Remove unnecessary mark_attr_used
1 parent a38f8fb commit 660d8a6

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
784784
}
785785
};
786786

787+
let attrs: Vec<_> = self.get_item_attrs(id, sess).collect();
787788
SyntaxExtension::new(
788789
sess,
789790
kind,
790791
self.get_span(id, sess),
791792
helper_attrs,
792793
self.root.edition,
793794
Symbol::intern(name),
794-
&self.get_item_attrs(id, sess),
795+
&attrs,
795796
)
796797
}
797798

@@ -1157,7 +1158,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11571158
// within the crate. We only need this for fictive constructors,
11581159
// for other constructors correct visibilities
11591160
// were already encoded in metadata.
1160-
let attrs = self.get_item_attrs(def_id.index, sess);
1161+
let attrs: Vec<_> =
1162+
self.get_item_attrs(def_id.index, sess).collect();
11611163
if sess.contains_name(&attrs, sym::non_exhaustive) {
11621164
let crate_def_id = self.local_def_id(CRATE_DEF_INDEX);
11631165
vis = ty::Visibility::Restricted(crate_def_id);
@@ -1283,8 +1285,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12831285
}
12841286
}
12851287

1286-
fn get_item_variances(&self, id: DefIndex) -> Vec<ty::Variance> {
1287-
self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self).collect()
1288+
fn get_item_variances(&'a self, id: DefIndex) -> impl Iterator<Item = ty::Variance> + 'a {
1289+
self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self)
12881290
}
12891291

12901292
fn get_ctor_kind(&self, node_id: DefIndex) -> CtorKind {
@@ -1308,7 +1310,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13081310
}
13091311
}
13101312

1311-
fn get_item_attrs(&self, node_id: DefIndex, sess: &Session) -> Vec<ast::Attribute> {
1313+
fn get_item_attrs(
1314+
&'a self,
1315+
node_id: DefIndex,
1316+
sess: &'a Session,
1317+
) -> impl Iterator<Item = ast::Attribute> + 'a {
13121318
// The attributes for a tuple struct/variant are attached to the definition, not the ctor;
13131319
// we assume that someone passing in a tuple struct ctor is actually wanting to
13141320
// look at the definition
@@ -1325,7 +1331,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13251331
.get(self, item_id)
13261332
.unwrap_or_else(Lazy::empty)
13271333
.decode((self, sess))
1328-
.collect::<Vec<_>>()
13291334
}
13301335

13311336
fn get_struct_field_names(&self, id: DefIndex, sess: &Session) -> Vec<Spanned<Symbol>> {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
138138
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
139139
}
140140
item_attrs => { tcx.arena.alloc_from_iter(
141-
cdata.get_item_attrs(def_id.index, tcx.sess).into_iter()
141+
cdata.get_item_attrs(def_id.index, tcx.sess)
142142
) }
143143
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
144144
rendered_const => { cdata.get_rendered_const(def_id.index) }
@@ -415,11 +415,7 @@ impl CStore {
415415

416416
let span = data.get_span(id.index, sess);
417417

418-
// Mark the attrs as used
419-
let attrs = data.get_item_attrs(id.index, sess);
420-
for attr in attrs.iter() {
421-
sess.mark_attr_used(attr);
422-
}
418+
let attrs: Vec<_> = data.get_item_attrs(id.index, sess).collect();
423419

424420
let ident = data.item_ident(id.index, sess);
425421

@@ -428,7 +424,7 @@ impl CStore {
428424
ident,
429425
id: ast::DUMMY_NODE_ID,
430426
span,
431-
attrs: attrs.to_vec(),
427+
attrs,
432428
kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)),
433429
vis: ast::Visibility {
434430
span: span.shrink_to_lo(),

0 commit comments

Comments
 (0)