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 } ;
@@ -222,13 +223,24 @@ impl<'a> CrateLoader<'a> {
222
223
crate_root. def_path_table . decode ( ( & metadata, self . sess ) )
223
224
} ) ;
224
225
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
+
225
237
let trait_impls = crate_root
226
238
. impls
227
239
. decode ( ( & metadata, self . sess ) )
228
240
. map ( |trait_impls| ( trait_impls. trait_id , trait_impls. impls ) )
229
241
. collect ( ) ;
230
242
231
- let mut cmeta = cstore:: CrateMetadata {
243
+ let cmeta = cstore:: CrateMetadata {
232
244
name,
233
245
extern_crate : Lock :: new ( None ) ,
234
246
def_path_table : Lrc :: new ( def_path_table) ,
@@ -248,17 +260,15 @@ impl<'a> CrateLoader<'a> {
248
260
rlib,
249
261
rmeta,
250
262
} ,
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" ) ,
258
270
} ;
259
271
260
- cmeta. derive_attributes ( self . sess ) ;
261
-
262
272
let cmeta = Lrc :: new ( cmeta) ;
263
273
self . cstore . set_crate_data ( cnum, cmeta. clone ( ) ) ;
264
274
( cnum, cmeta)
@@ -651,12 +661,12 @@ impl<'a> CrateLoader<'a> {
651
661
652
662
self . cstore . iter_crate_data ( |cnum, data| {
653
663
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 {
656
666
// Inject a dependency from all #![needs_panic_runtime] to this
657
667
// #![panic_runtime] crate.
658
668
self . inject_dependency_if ( cnum, "a panic runtime" ,
659
- & |data| data. needs_panic_runtime ( ) ) ;
669
+ & |data| data. needs_panic_runtime ) ;
660
670
runtime_found = runtime_found || * data. dep_kind . lock ( ) == DepKind :: Explicit ;
661
671
}
662
672
} ) ;
@@ -693,7 +703,7 @@ impl<'a> CrateLoader<'a> {
693
703
694
704
// Sanity check the loaded crate to ensure it is indeed a panic runtime
695
705
// and the panic strategy is indeed what we thought it was.
696
- if !data. is_panic_runtime ( ) {
706
+ if !data. panic_runtime {
697
707
self . sess . err ( & format ! ( "the crate `{}` is not a panic runtime" ,
698
708
name) ) ;
699
709
}
@@ -705,7 +715,7 @@ impl<'a> CrateLoader<'a> {
705
715
706
716
self . sess . injected_panic_runtime . set ( Some ( cnum) ) ;
707
717
self . inject_dependency_if ( cnum, "a panic runtime" ,
708
- & |data| data. needs_panic_runtime ( ) ) ;
718
+ & |data| data. needs_panic_runtime ) ;
709
719
}
710
720
711
721
fn inject_sanitizer_runtime ( & mut self ) {
@@ -800,7 +810,7 @@ impl<'a> CrateLoader<'a> {
800
810
PathKind :: Crate , dep_kind) ;
801
811
802
812
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
803
- if !data. is_sanitizer_runtime ( ) {
813
+ if !data. sanitizer_runtime {
804
814
self . sess . err ( & format ! ( "the crate `{}` is not a sanitizer runtime" ,
805
815
name) ) ;
806
816
}
@@ -823,7 +833,7 @@ impl<'a> CrateLoader<'a> {
823
833
PathKind :: Crate , dep_kind) ;
824
834
825
835
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
826
- if !data. is_profiler_runtime ( ) {
836
+ if !data. profiler_runtime {
827
837
self . sess . err ( & format ! ( "the crate `profiler_builtins` is not \
828
838
a profiler runtime") ) ;
829
839
}
@@ -840,7 +850,7 @@ impl<'a> CrateLoader<'a> {
840
850
let mut needs_allocator = attr:: contains_name ( & krate. attrs ,
841
851
"needs_allocator" ) ;
842
852
self . cstore . iter_crate_data ( |_, data| {
843
- needs_allocator = needs_allocator || data. needs_allocator ( ) ;
853
+ needs_allocator = needs_allocator || data. needs_allocator ;
844
854
} ) ;
845
855
if !needs_allocator {
846
856
self . sess . injected_allocator . set ( None ) ;
0 commit comments