11
11
//! Validates all used crates and extern libraries and loads their metadata
12
12
13
13
use cstore:: { self , CStore , CrateSource , MetadataBlob } ;
14
+ use decoder:: Metadata ;
14
15
use locator:: { self , CratePaths } ;
15
16
use schema:: CrateRoot ;
16
17
use rustc_data_structures:: sync:: { Lrc , RwLock , Lock } ;
@@ -220,13 +221,24 @@ impl<'a> CrateLoader<'a> {
220
221
crate_root. def_path_table . decode ( ( & metadata, self . sess ) )
221
222
} ) ;
222
223
224
+ let crate_entry = crate_root
225
+ . index
226
+ . lookup ( metadata. raw_bytes ( ) , CRATE_DEF_INDEX )
227
+ . unwrap ( )
228
+ . decode ( & metadata) ;
229
+
230
+ let crate_attrs: Vec < ast:: Attribute > = crate_entry
231
+ . attributes
232
+ . decode ( ( & metadata, self . sess ) )
233
+ . collect ( ) ;
234
+
223
235
let trait_impls = crate_root
224
236
. impls
225
237
. decode ( ( & metadata, self . sess ) )
226
238
. map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
227
239
. collect ( ) ;
228
240
229
- let mut cmeta = cstore:: CrateMetadata {
241
+ let cmeta = cstore:: CrateMetadata {
230
242
name,
231
243
extern_crate : Lock :: new ( None ) ,
232
244
def_path_table : Lrc :: new ( def_path_table) ,
@@ -246,17 +258,15 @@ impl<'a> CrateLoader<'a> {
246
258
rlib,
247
259
rmeta,
248
260
} ,
249
- compiler_builtins : None ,
250
- needs_allocator : None ,
251
- needs_panic_runtime : None ,
252
- no_builtins : None ,
253
- panic_runtime : None ,
254
- profiler_runtime : None ,
255
- sanitizer_runtime : None ,
261
+ compiler_builtins : attr :: contains_name ( & crate_attrs , "compiler_builtins" ) ,
262
+ needs_allocator : attr :: contains_name ( & crate_attrs , "needs_allocator" ) ,
263
+ needs_panic_runtime : attr :: contains_name ( & crate_attrs , "needs_panic_runtime" ) ,
264
+ no_builtins : attr :: contains_name ( & crate_attrs , "no_builtins" ) ,
265
+ panic_runtime : attr :: contains_name ( & crate_attrs , "panic_runtime" ) ,
266
+ profiler_runtime : attr :: contains_name ( & crate_attrs , "profiler_runtime" ) ,
267
+ sanitizer_runtime : attr :: contains_name ( & crate_attrs , "sanitizer_runtime" ) ,
256
268
} ;
257
269
258
- cmeta. derive_attributes ( self . sess ) ;
259
-
260
270
let cmeta = Lrc :: new ( cmeta) ;
261
271
self . cstore . set_crate_data ( cnum, cmeta. clone ( ) ) ;
262
272
( cnum, cmeta)
@@ -644,12 +654,12 @@ impl<'a> CrateLoader<'a> {
644
654
645
655
self . cstore . iter_crate_data ( |cnum, data| {
646
656
needs_panic_runtime = needs_panic_runtime ||
647
- data. needs_panic_runtime ( ) ;
648
- if data. is_panic_runtime ( ) {
657
+ data. needs_panic_runtime ;
658
+ if data. panic_runtime {
649
659
// Inject a dependency from all #![needs_panic_runtime] to this
650
660
// #![panic_runtime] crate.
651
661
self . inject_dependency_if ( cnum, "a panic runtime" ,
652
- & |data| data. needs_panic_runtime ( ) ) ;
662
+ & |data| data. needs_panic_runtime ) ;
653
663
runtime_found = runtime_found || * data. dep_kind . lock ( ) == DepKind :: Explicit ;
654
664
}
655
665
} ) ;
@@ -686,7 +696,7 @@ impl<'a> CrateLoader<'a> {
686
696
687
697
// Sanity check the loaded crate to ensure it is indeed a panic runtime
688
698
// and the panic strategy is indeed what we thought it was.
689
- if !data. is_panic_runtime ( ) {
699
+ if !data. panic_runtime {
690
700
self . sess . err ( & format ! ( "the crate `{}` is not a panic runtime" ,
691
701
name) ) ;
692
702
}
@@ -698,7 +708,7 @@ impl<'a> CrateLoader<'a> {
698
708
699
709
self . sess . injected_panic_runtime . set ( Some ( cnum) ) ;
700
710
self . inject_dependency_if ( cnum, "a panic runtime" ,
701
- & |data| data. needs_panic_runtime ( ) ) ;
711
+ & |data| data. needs_panic_runtime ) ;
702
712
}
703
713
704
714
fn inject_sanitizer_runtime ( & mut self ) {
@@ -793,7 +803,7 @@ impl<'a> CrateLoader<'a> {
793
803
PathKind :: Crate , dep_kind) ;
794
804
795
805
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
796
- if !data. is_sanitizer_runtime ( ) {
806
+ if !data. sanitizer_runtime {
797
807
self . sess . err ( & format ! ( "the crate `{}` is not a sanitizer runtime" ,
798
808
name) ) ;
799
809
}
@@ -816,7 +826,7 @@ impl<'a> CrateLoader<'a> {
816
826
PathKind :: Crate , dep_kind) ;
817
827
818
828
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
819
- if !data. is_profiler_runtime ( ) {
829
+ if !data. profiler_runtime {
820
830
self . sess . err ( & format ! ( "the crate `profiler_builtins` is not \
821
831
a profiler runtime") ) ;
822
832
}
@@ -833,7 +843,7 @@ impl<'a> CrateLoader<'a> {
833
843
let mut needs_allocator = attr:: contains_name ( & krate. attrs ,
834
844
"needs_allocator" ) ;
835
845
self . cstore . iter_crate_data ( |_, data| {
836
- needs_allocator = needs_allocator || data. needs_allocator ( ) ;
846
+ needs_allocator = needs_allocator || data. needs_allocator ;
837
847
} ) ;
838
848
if !needs_allocator {
839
849
self . sess . injected_allocator . set ( None ) ;
0 commit comments