@@ -692,6 +692,8 @@ impl<'a, 'tcx> CrateMetadata {
692692
693693 /// Iterates over all the stability attributes in the given crate.
694694 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.
695697 self . root
696698 . lib_features
697699 . decode ( self )
@@ -700,11 +702,16 @@ impl<'a, 'tcx> CrateMetadata {
700702
701703 /// Iterates over the language items in the given crate.
702704 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+ }
708715 }
709716
710717 /// Iterates over each child of the given item.
@@ -978,12 +985,16 @@ impl<'a, 'tcx> CrateMetadata {
978985 pub fn get_implementations_for_trait ( & self ,
979986 filter : Option < DefId > ,
980987 result : & mut Vec < DefId > ) {
988+ if self . proc_macros . is_some ( ) {
989+ // proc-macro crates export no trait impls.
990+ return
991+ }
992+
981993 // Do a reverse lookup beforehand to avoid touching the crate_num
982994 // hash map in the loop below.
983995 let filter = match filter. map ( |def_id| self . reverse_translate_def_id ( def_id) ) {
984996 Some ( Some ( def_id) ) => Some ( ( def_id. krate . as_u32 ( ) , def_id. index ) ) ,
985997 Some ( None ) => return ,
986- None if self . proc_macros . is_some ( ) => return ,
987998 None => None ,
988999 } ;
9891000
@@ -1016,11 +1027,21 @@ impl<'a, 'tcx> CrateMetadata {
10161027
10171028
10181029 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+ }
10201036 }
10211037
10221038 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+ }
10241045 }
10251046
10261047 pub fn get_dylib_dependency_formats ( & self ) -> Vec < ( CrateNum , LinkagePreference ) > {
@@ -1036,10 +1057,15 @@ impl<'a, 'tcx> CrateMetadata {
10361057 }
10371058
10381059 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+ }
10431069 }
10441070
10451071 pub fn get_fn_arg_names ( & self , id : DefIndex ) -> Vec < ast:: Name > {
@@ -1055,10 +1081,16 @@ impl<'a, 'tcx> CrateMetadata {
10551081 pub fn exported_symbols ( & self ,
10561082 tcx : TyCtxt < ' a , ' tcx , ' tcx > )
10571083 -> 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+ }
10621094 }
10631095
10641096 pub fn get_rendered_const ( & self , id : DefIndex ) -> String {
@@ -1149,9 +1181,12 @@ impl<'a, 'tcx> CrateMetadata {
11491181 /// file they represent, just information about length, line breaks, and
11501182 /// multibyte characters. This information is enough to generate valid debuginfo
11511183 /// 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.
11521187 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 > > {
11551190 {
11561191 let source_files = self . source_map_import_info . borrow ( ) ;
11571192 if !source_files. is_empty ( ) {
0 commit comments