11// Decoding metadata from a single crate's metadata
22
3+ use crate :: creader:: CrateMetadataRef ;
34use crate :: rmeta:: table:: { FixedSizeEncoding , Table } ;
45use crate :: rmeta:: * ;
56
@@ -125,7 +126,7 @@ struct ImportedSourceFile {
125126
126127pub ( super ) struct DecodeContext < ' a , ' tcx > {
127128 opaque : opaque:: Decoder < ' a > ,
128- cdata : Option < & ' a CrateMetadata > ,
129+ cdata : Option < CrateMetadataRef < ' a > > ,
129130 sess : Option < & ' tcx Session > ,
130131 tcx : Option < TyCtxt < ' tcx > > ,
131132
@@ -141,7 +142,7 @@ pub(super) struct DecodeContext<'a, 'tcx> {
141142/// Abstract over the various ways one can create metadata decoders.
142143pub ( super ) trait Metadata < ' a , ' tcx > : Copy {
143144 fn raw_bytes ( self ) -> & ' a [ u8 ] ;
144- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
145+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
145146 None
146147 }
147148 fn sess ( self ) -> Option < & ' tcx Session > {
@@ -162,7 +163,7 @@ pub(super) trait Metadata<'a, 'tcx>: Copy {
162163 lazy_state : LazyState :: NoNode ,
163164 alloc_decoding_session : self
164165 . cdata ( )
165- . map ( |cdata| cdata. alloc_decoding_state . new_decoding_session ( ) ) ,
166+ . map ( |cdata| cdata. cdata . alloc_decoding_state . new_decoding_session ( ) ) ,
166167 }
167168 }
168169}
@@ -185,33 +186,33 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a MetadataBlob, &'tcx Session) {
185186 }
186187}
187188
188- impl < ' a , ' tcx > Metadata < ' a , ' tcx > for & ' a CrateMetadata {
189+ impl < ' a , ' tcx > Metadata < ' a , ' tcx > for & ' a CrateMetadataRef < ' a > {
189190 fn raw_bytes ( self ) -> & ' a [ u8 ] {
190191 self . blob . raw_bytes ( )
191192 }
192- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
193- Some ( self )
193+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
194+ Some ( * self )
194195 }
195196}
196197
197- impl < ' a , ' tcx > Metadata < ' a , ' tcx > for ( & ' a CrateMetadata , & ' tcx Session ) {
198+ impl < ' a , ' tcx > Metadata < ' a , ' tcx > for ( & ' a CrateMetadataRef < ' a > , & ' tcx Session ) {
198199 fn raw_bytes ( self ) -> & ' a [ u8 ] {
199200 self . 0 . raw_bytes ( )
200201 }
201- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
202- Some ( self . 0 )
202+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
203+ Some ( * self . 0 )
203204 }
204205 fn sess ( self ) -> Option < & ' tcx Session > {
205206 Some ( & self . 1 )
206207 }
207208}
208209
209- impl < ' a , ' tcx > Metadata < ' a , ' tcx > for ( & ' a CrateMetadata , TyCtxt < ' tcx > ) {
210+ impl < ' a , ' tcx > Metadata < ' a , ' tcx > for ( & ' a CrateMetadataRef < ' a > , TyCtxt < ' tcx > ) {
210211 fn raw_bytes ( self ) -> & ' a [ u8 ] {
211212 self . 0 . raw_bytes ( )
212213 }
213- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
214- Some ( self . 0 )
214+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
215+ Some ( * self . 0 )
215216 }
216217 fn tcx ( self ) -> Option < TyCtxt < ' tcx > > {
217218 Some ( self . 1 )
@@ -242,7 +243,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
242243 self . tcx . expect ( "missing TyCtxt in DecodeContext" )
243244 }
244245
245- fn cdata ( & self ) -> & ' a CrateMetadata {
246+ fn cdata ( & self ) -> CrateMetadataRef < ' a > {
246247 self . cdata . expect ( "missing CrateMetadata in DecodeContext" )
247248 }
248249
@@ -558,7 +559,7 @@ impl CrateRoot<'_> {
558559 }
559560}
560561
561- impl < ' a , ' tcx > CrateMetadata {
562+ impl CrateMetadata {
562563 crate fn new (
563564 sess : & Session ,
564565 blob : MetadataBlob ,
@@ -601,7 +602,9 @@ impl<'a, 'tcx> CrateMetadata {
601602 extern_crate : Lock :: new ( None ) ,
602603 }
603604 }
605+ }
604606
607+ impl < ' a , ' tcx > CrateMetadataRef < ' a > {
605608 fn is_proc_macro ( & self , id : DefIndex ) -> bool {
606609 self . root . proc_macro_data . and_then ( |data| data. decode ( self ) . find ( |x| * x == id) ) . is_some ( )
607610 }
@@ -1440,10 +1443,10 @@ impl<'a, 'tcx> CrateMetadata {
14401443 /// Proc macro crates don't currently export spans, so this function does not have
14411444 /// to work for them.
14421445 fn imported_source_files (
1443- & ' a self ,
1446+ & self ,
14441447 local_source_map : & source_map:: SourceMap ,
1445- ) -> & [ ImportedSourceFile ] {
1446- self . source_map_import_info . init_locking ( || {
1448+ ) -> & ' a [ ImportedSourceFile ] {
1449+ self . cdata . source_map_import_info . init_locking ( || {
14471450 let external_source_map = self . root . source_map . decode ( self ) ;
14481451
14491452 external_source_map
@@ -1540,7 +1543,9 @@ impl<'a, 'tcx> CrateMetadata {
15401543
15411544 dep_node_index
15421545 }
1546+ }
15431547
1548+ impl CrateMetadata {
15441549 crate fn dependencies ( & self ) -> LockGuard < ' _ , Vec < CrateNum > > {
15451550 self . dependencies . borrow ( )
15461551 }
0 commit comments