@@ -1033,45 +1033,33 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1033
1033
1034
1034
/// Iterates over all the stability attributes in the given crate.
1035
1035
fn get_lib_features(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] {
1036
- // FIXME: For a proc macro crate, not sure whether we should return the "host"
1037
- // features or an empty Vec. Both don't cause ICEs.
1038
1036
tcx.arena.alloc_from_iter(self.root.lib_features.decode(self))
1039
1037
}
1040
1038
1041
1039
/// Iterates over the language items in the given crate.
1042
1040
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
1043
- if self.root.is_proc_macro_crate() {
1044
- // Proc macro crates do not export any lang-items to the target.
1045
- &[]
1046
- } else {
1047
- tcx.arena.alloc_from_iter(
1048
- self.root
1049
- .lang_items
1050
- .decode(self)
1051
- .map(|(def_index, index)| (self.local_def_id(def_index), index)),
1052
- )
1053
- }
1041
+ tcx.arena.alloc_from_iter(
1042
+ self.root
1043
+ .lang_items
1044
+ .decode(self)
1045
+ .map(|(def_index, index)| (self.local_def_id(def_index), index)),
1046
+ )
1054
1047
}
1055
1048
1056
1049
/// Iterates over the diagnostic items in the given crate.
1057
1050
fn get_diagnostic_items(self) -> DiagnosticItems {
1058
- if self.root.is_proc_macro_crate() {
1059
- // Proc macro crates do not export any diagnostic-items to the target.
1060
- Default::default()
1061
- } else {
1062
- let mut id_to_name = FxHashMap::default();
1063
- let name_to_id = self
1064
- .root
1065
- .diagnostic_items
1066
- .decode(self)
1067
- .map(|(name, def_index)| {
1068
- let id = self.local_def_id(def_index);
1069
- id_to_name.insert(id, name);
1070
- (name, id)
1071
- })
1072
- .collect();
1073
- DiagnosticItems { id_to_name, name_to_id }
1074
- }
1051
+ let mut id_to_name = FxHashMap::default();
1052
+ let name_to_id = self
1053
+ .root
1054
+ .diagnostic_items
1055
+ .decode(self)
1056
+ .map(|(name, def_index)| {
1057
+ let id = self.local_def_id(def_index);
1058
+ id_to_name.insert(id, name);
1059
+ (name, id)
1060
+ })
1061
+ .collect();
1062
+ DiagnosticItems { id_to_name, name_to_id }
1075
1063
}
1076
1064
1077
1065
/// Iterates over all named children of the given module,
@@ -1346,26 +1334,28 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1346
1334
.decode((self, sess))
1347
1335
}
1348
1336
1349
- fn get_struct_field_names(self, id: DefIndex, sess: &Session) -> Vec<Spanned<Symbol>> {
1337
+ fn get_struct_field_names(
1338
+ self,
1339
+ id: DefIndex,
1340
+ sess: &'a Session,
1341
+ ) -> impl Iterator<Item = Spanned<Symbol>> + 'a {
1350
1342
self.root
1351
1343
.tables
1352
1344
.children
1353
1345
.get(self, id)
1354
1346
.unwrap_or_else(Lazy::empty)
1355
1347
.decode(self)
1356
- .map(|index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
1357
- .collect()
1348
+ .map(move |index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
1358
1349
}
1359
1350
1360
- fn get_struct_field_visibilities(self, id: DefIndex) -> Vec< Visibility> {
1351
+ fn get_struct_field_visibilities(self, id: DefIndex) -> impl Iterator<Item = Visibility> + 'a {
1361
1352
self.root
1362
1353
.tables
1363
1354
.children
1364
1355
.get(self, id)
1365
1356
.unwrap_or_else(Lazy::empty)
1366
1357
.decode(self)
1367
- .map(|field_index| self.get_visibility(field_index))
1368
- .collect()
1358
+ .map(move |field_index| self.get_visibility(field_index))
1369
1359
}
1370
1360
1371
1361
fn get_inherent_implementations_for_type(
@@ -1401,8 +1391,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1401
1391
tcx: TyCtxt<'tcx>,
1402
1392
trait_def_id: DefId,
1403
1393
) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1404
- if self.root.is_proc_macro_crate() {
1405
- // proc-macro crates export no trait impls.
1394
+ if self.trait_impls.is_empty() {
1406
1395
return &[];
1407
1396
}
1408
1397
@@ -1437,13 +1426,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1437
1426
})
1438
1427
}
1439
1428
1440
- fn get_native_libraries(self, sess: &Session) -> Vec<NativeLib> {
1441
- if self.root.is_proc_macro_crate() {
1442
- // Proc macro crates do not have any *target* native libraries.
1443
- vec![]
1444
- } else {
1445
- self.root.native_libraries.decode((self, sess)).collect()
1446
- }
1429
+ fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
1430
+ self.root.native_libraries.decode((self, sess))
1447
1431
}
1448
1432
1449
1433
fn get_proc_macro_quoted_span(self, index: usize, sess: &Session) -> Span {
@@ -1455,15 +1439,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1455
1439
.decode((self, sess))
1456
1440
}
1457
1441
1458
- fn get_foreign_modules(self, tcx: TyCtxt<'tcx>) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1459
- if self.root.is_proc_macro_crate() {
1460
- // Proc macro crates do not have any *target* foreign modules.
1461
- Lrc::new(FxHashMap::default())
1462
- } else {
1463
- let modules: FxHashMap<DefId, ForeignModule> =
1464
- self.root.foreign_modules.decode((self, tcx.sess)).map(|m| (m.def_id, m)).collect();
1465
- Lrc::new(modules)
1466
- }
1442
+ fn get_foreign_modules(self, sess: &'a Session) -> impl Iterator<Item = ForeignModule> + '_ {
1443
+ self.root.foreign_modules.decode((self, sess))
1467
1444
}
1468
1445
1469
1446
fn get_dylib_dependency_formats(
@@ -1479,12 +1456,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1479
1456
}
1480
1457
1481
1458
fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangItem] {
1482
- if self.root.is_proc_macro_crate() {
1483
- // Proc macro crates do not depend on any target weak lang-items.
1484
- &[]
1485
- } else {
1486
- tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self))
1487
- }
1459
+ tcx.arena.alloc_from_iter(self.root.lang_items_missing.decode(self))
1488
1460
}
1489
1461
1490
1462
fn get_fn_param_names(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] {
@@ -1500,13 +1472,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1500
1472
self,
1501
1473
tcx: TyCtxt<'tcx>,
1502
1474
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1503
- if self.root.is_proc_macro_crate() {
1504
- // If this crate is a custom derive crate, then we're not even going to
1505
- // link those in so we skip those crates.
1506
- &[]
1507
- } else {
1508
- tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
1509
- }
1475
+ tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
1510
1476
}
1511
1477
1512
1478
fn get_rendered_const(self, id: DefIndex) -> String {
0 commit comments