@@ -692,6 +692,8 @@ impl<'a, 'tcx> CrateMetadata {
692
692
693
693
/// Iterates over all the stability attributes in the given crate.
694
694
pub fn get_lib_features ( & self ) -> Vec < ( ast:: Name , Option < ast:: Name > ) > {
695
+ // FIXME: For a proc macro crate, not sure whether we should return the "host"
696
+ // features or an empty Vec. Both don't cause ICEs.
695
697
self . root
696
698
. lib_features
697
699
. decode ( self )
@@ -700,11 +702,16 @@ impl<'a, 'tcx> CrateMetadata {
700
702
701
703
/// Iterates over the language items in the given crate.
702
704
pub fn get_lang_items ( & self ) -> Vec < ( DefId , usize ) > {
703
- self . root
704
- . lang_items
705
- . decode ( self )
706
- . map ( |( def_index, index) | ( self . local_def_id ( def_index) , index) )
707
- . collect ( )
705
+ if self . proc_macros . is_some ( ) {
706
+ // Proc macro crates do not export any lang-items to the target.
707
+ vec ! [ ]
708
+ } else {
709
+ self . root
710
+ . lang_items
711
+ . decode ( self )
712
+ . map ( |( def_index, index) | ( self . local_def_id ( def_index) , index) )
713
+ . collect ( )
714
+ }
708
715
}
709
716
710
717
/// Iterates over each child of the given item.
@@ -978,12 +985,16 @@ impl<'a, 'tcx> CrateMetadata {
978
985
pub fn get_implementations_for_trait ( & self ,
979
986
filter : Option < DefId > ,
980
987
result : & mut Vec < DefId > ) {
988
+ if self . proc_macros . is_some ( ) {
989
+ // proc-macro crates export no trait impls.
990
+ return
991
+ }
992
+
981
993
// Do a reverse lookup beforehand to avoid touching the crate_num
982
994
// hash map in the loop below.
983
995
let filter = match filter. map ( |def_id| self . reverse_translate_def_id ( def_id) ) {
984
996
Some ( Some ( def_id) ) => Some ( ( def_id. krate . as_u32 ( ) , def_id. index ) ) ,
985
997
Some ( None ) => return ,
986
- None if self . proc_macros . is_some ( ) => return ,
987
998
None => None ,
988
999
} ;
989
1000
@@ -1016,11 +1027,21 @@ impl<'a, 'tcx> CrateMetadata {
1016
1027
1017
1028
1018
1029
pub fn get_native_libraries ( & self , sess : & Session ) -> Vec < NativeLibrary > {
1019
- self . root . native_libraries . decode ( ( self , sess) ) . collect ( )
1030
+ if self . proc_macros . is_some ( ) {
1031
+ // Proc macro crates do not have any *target* native libraries.
1032
+ vec ! [ ]
1033
+ } else {
1034
+ self . root . native_libraries . decode ( ( self , sess) ) . collect ( )
1035
+ }
1020
1036
}
1021
1037
1022
1038
pub fn get_foreign_modules ( & self , sess : & Session ) -> Vec < ForeignModule > {
1023
- self . root . foreign_modules . decode ( ( self , sess) ) . collect ( )
1039
+ if self . proc_macros . is_some ( ) {
1040
+ // Proc macro crates do not have any *target* foreign modules.
1041
+ vec ! [ ]
1042
+ } else {
1043
+ self . root . foreign_modules . decode ( ( self , sess) ) . collect ( )
1044
+ }
1024
1045
}
1025
1046
1026
1047
pub fn get_dylib_dependency_formats ( & self ) -> Vec < ( CrateNum , LinkagePreference ) > {
@@ -1036,10 +1057,15 @@ impl<'a, 'tcx> CrateMetadata {
1036
1057
}
1037
1058
1038
1059
pub fn get_missing_lang_items ( & self ) -> Vec < lang_items:: LangItem > {
1039
- self . root
1040
- . lang_items_missing
1041
- . decode ( self )
1042
- . collect ( )
1060
+ if self . proc_macros . is_some ( ) {
1061
+ // Proc macro crates do not depend on any target weak lang-items.
1062
+ vec ! [ ]
1063
+ } else {
1064
+ self . root
1065
+ . lang_items_missing
1066
+ . decode ( self )
1067
+ . collect ( )
1068
+ }
1043
1069
}
1044
1070
1045
1071
pub fn get_fn_arg_names ( & self , id : DefIndex ) -> Vec < ast:: Name > {
@@ -1055,10 +1081,16 @@ impl<'a, 'tcx> CrateMetadata {
1055
1081
pub fn exported_symbols ( & self ,
1056
1082
tcx : TyCtxt < ' a , ' tcx , ' tcx > )
1057
1083
-> Vec < ( ExportedSymbol < ' tcx > , SymbolExportLevel ) > {
1058
- let lazy_seq: LazySeq < ( ExportedSymbol < ' tcx > , SymbolExportLevel ) > =
1059
- LazySeq :: with_position_and_length ( self . root . exported_symbols . position ,
1060
- self . root . exported_symbols . len ) ;
1061
- lazy_seq. decode ( ( self , tcx) ) . collect ( )
1084
+ if self . proc_macros . is_some ( ) {
1085
+ // If this crate is a custom derive crate, then we're not even going to
1086
+ // link those in so we skip those crates.
1087
+ vec ! [ ]
1088
+ } else {
1089
+ let lazy_seq: LazySeq < ( ExportedSymbol < ' tcx > , SymbolExportLevel ) > =
1090
+ LazySeq :: with_position_and_length ( self . root . exported_symbols . position ,
1091
+ self . root . exported_symbols . len ) ;
1092
+ lazy_seq. decode ( ( self , tcx) ) . collect ( )
1093
+ }
1062
1094
}
1063
1095
1064
1096
pub fn get_rendered_const ( & self , id : DefIndex ) -> String {
@@ -1149,9 +1181,12 @@ impl<'a, 'tcx> CrateMetadata {
1149
1181
/// file they represent, just information about length, line breaks, and
1150
1182
/// multibyte characters. This information is enough to generate valid debuginfo
1151
1183
/// for items inlined from other crates.
1184
+ ///
1185
+ /// Proc macro crates don't currently export spans, so this function does not have
1186
+ /// to work for them.
1152
1187
pub fn imported_source_files ( & ' a self ,
1153
- local_source_map : & source_map:: SourceMap )
1154
- -> ReadGuard < ' a , Vec < cstore:: ImportedSourceFile > > {
1188
+ local_source_map : & source_map:: SourceMap )
1189
+ -> ReadGuard < ' a , Vec < cstore:: ImportedSourceFile > > {
1155
1190
{
1156
1191
let source_files = self . source_map_import_info . borrow ( ) ;
1157
1192
if !source_files. is_empty ( ) {
0 commit comments