1111//! Validates all used crates and extern libraries and loads their metadata
1212
1313use cstore:: { self , CStore , CrateSource , MetadataBlob } ;
14+ use decoder:: Metadata ;
1415use locator:: { self , CratePaths } ;
1516use schema:: CrateRoot ;
1617use rustc_data_structures:: sync:: { Lrc , RwLock , Lock } ;
@@ -222,13 +223,24 @@ impl<'a> CrateLoader<'a> {
222223 crate_root. def_path_table . decode ( ( & metadata, self . sess ) )
223224 } ) ;
224225
226+ let crate_entry = crate_root
227+ . index
228+ . lookup ( metadata. raw_bytes ( ) , CRATE_DEF_INDEX )
229+ . unwrap ( )
230+ . decode ( & metadata) ;
231+
232+ let crate_attrs: Vec < ast:: Attribute > = crate_entry
233+ . attributes
234+ . decode ( ( & metadata, self . sess ) )
235+ . collect ( ) ;
236+
225237 let trait_impls = crate_root
226238 . impls
227239 . decode ( ( & metadata, self . sess ) )
228240 . map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
229241 . collect ( ) ;
230242
231- let mut cmeta = cstore:: CrateMetadata {
243+ let cmeta = cstore:: CrateMetadata {
232244 name,
233245 extern_crate : Lock :: new ( None ) ,
234246 def_path_table : Lrc :: new ( def_path_table) ,
@@ -248,17 +260,15 @@ impl<'a> CrateLoader<'a> {
248260 rlib,
249261 rmeta,
250262 } ,
251- compiler_builtins : None ,
252- needs_allocator : None ,
253- needs_panic_runtime : None ,
254- no_builtins : None ,
255- panic_runtime : None ,
256- profiler_runtime : None ,
257- sanitizer_runtime : None ,
263+ compiler_builtins : attr :: contains_name ( & crate_attrs , "compiler_builtins" ) ,
264+ needs_allocator : attr :: contains_name ( & crate_attrs , "needs_allocator" ) ,
265+ needs_panic_runtime : attr :: contains_name ( & crate_attrs , "needs_panic_runtime" ) ,
266+ no_builtins : attr :: contains_name ( & crate_attrs , "no_builtins" ) ,
267+ panic_runtime : attr :: contains_name ( & crate_attrs , "panic_runtime" ) ,
268+ profiler_runtime : attr :: contains_name ( & crate_attrs , "profiler_runtime" ) ,
269+ sanitizer_runtime : attr :: contains_name ( & crate_attrs , "sanitizer_runtime" ) ,
258270 } ;
259271
260- cmeta. derive_attributes ( self . sess ) ;
261-
262272 let cmeta = Lrc :: new ( cmeta) ;
263273 self . cstore . set_crate_data ( cnum, cmeta. clone ( ) ) ;
264274 ( cnum, cmeta)
@@ -651,12 +661,12 @@ impl<'a> CrateLoader<'a> {
651661
652662 self . cstore . iter_crate_data ( |cnum, data| {
653663 needs_panic_runtime = needs_panic_runtime ||
654- data. needs_panic_runtime ( ) ;
655- if data. is_panic_runtime ( ) {
664+ data. needs_panic_runtime ;
665+ if data. panic_runtime {
656666 // Inject a dependency from all #![needs_panic_runtime] to this
657667 // #![panic_runtime] crate.
658668 self . inject_dependency_if ( cnum, "a panic runtime" ,
659- & |data| data. needs_panic_runtime ( ) ) ;
669+ & |data| data. needs_panic_runtime ) ;
660670 runtime_found = runtime_found || * data. dep_kind . lock ( ) == DepKind :: Explicit ;
661671 }
662672 } ) ;
@@ -693,7 +703,7 @@ impl<'a> CrateLoader<'a> {
693703
694704 // Sanity check the loaded crate to ensure it is indeed a panic runtime
695705 // and the panic strategy is indeed what we thought it was.
696- if !data. is_panic_runtime ( ) {
706+ if !data. panic_runtime {
697707 self . sess . err ( & format ! ( "the crate `{}` is not a panic runtime" ,
698708 name) ) ;
699709 }
@@ -705,7 +715,7 @@ impl<'a> CrateLoader<'a> {
705715
706716 self . sess . injected_panic_runtime . set ( Some ( cnum) ) ;
707717 self . inject_dependency_if ( cnum, "a panic runtime" ,
708- & |data| data. needs_panic_runtime ( ) ) ;
718+ & |data| data. needs_panic_runtime ) ;
709719 }
710720
711721 fn inject_sanitizer_runtime ( & mut self ) {
@@ -800,7 +810,7 @@ impl<'a> CrateLoader<'a> {
800810 PathKind :: Crate , dep_kind) ;
801811
802812 // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
803- if !data. is_sanitizer_runtime ( ) {
813+ if !data. sanitizer_runtime {
804814 self . sess . err ( & format ! ( "the crate `{}` is not a sanitizer runtime" ,
805815 name) ) ;
806816 }
@@ -823,7 +833,7 @@ impl<'a> CrateLoader<'a> {
823833 PathKind :: Crate , dep_kind) ;
824834
825835 // Sanity check the loaded crate to ensure it is indeed a profiler runtime
826- if !data. is_profiler_runtime ( ) {
836+ if !data. profiler_runtime {
827837 self . sess . err ( & format ! ( "the crate `profiler_builtins` is not \
828838 a profiler runtime") ) ;
829839 }
@@ -840,7 +850,7 @@ impl<'a> CrateLoader<'a> {
840850 let mut needs_allocator = attr:: contains_name ( & krate. attrs ,
841851 "needs_allocator" ) ;
842852 self . cstore . iter_crate_data ( |_, data| {
843- needs_allocator = needs_allocator || data. needs_allocator ( ) ;
853+ needs_allocator = needs_allocator || data. needs_allocator ;
844854 } ) ;
845855 if !needs_allocator {
846856 self . sess . injected_allocator . set ( None ) ;
0 commit comments