1
1
// Decoding metadata from a single crate's metadata
2
2
3
+ use crate :: creader:: CrateMetadataRef ;
3
4
use crate :: rmeta:: table:: { FixedSizeEncoding , Table } ;
4
5
use crate :: rmeta:: * ;
5
6
@@ -125,7 +126,7 @@ struct ImportedSourceFile {
125
126
126
127
pub ( super ) struct DecodeContext < ' a , ' tcx > {
127
128
opaque : opaque:: Decoder < ' a > ,
128
- cdata : Option < & ' a CrateMetadata > ,
129
+ cdata : Option < CrateMetadataRef < ' a > > ,
129
130
sess : Option < & ' tcx Session > ,
130
131
tcx : Option < TyCtxt < ' tcx > > ,
131
132
@@ -141,7 +142,7 @@ pub(super) struct DecodeContext<'a, 'tcx> {
141
142
/// Abstract over the various ways one can create metadata decoders.
142
143
pub ( super ) trait Metadata < ' a , ' tcx > : Copy {
143
144
fn raw_bytes ( self ) -> & ' a [ u8 ] ;
144
- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
145
+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
145
146
None
146
147
}
147
148
fn sess ( self ) -> Option < & ' tcx Session > {
@@ -162,7 +163,7 @@ pub(super) trait Metadata<'a, 'tcx>: Copy {
162
163
lazy_state : LazyState :: NoNode ,
163
164
alloc_decoding_session : self
164
165
. cdata ( )
165
- . map ( |cdata| cdata. alloc_decoding_state . new_decoding_session ( ) ) ,
166
+ . map ( |cdata| cdata. cdata . alloc_decoding_state . new_decoding_session ( ) ) ,
166
167
}
167
168
}
168
169
}
@@ -185,33 +186,33 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a MetadataBlob, &'tcx Session) {
185
186
}
186
187
}
187
188
188
- impl < ' a , ' tcx > Metadata < ' a , ' tcx > for & ' a CrateMetadata {
189
+ impl < ' a , ' tcx > Metadata < ' a , ' tcx > for & ' a CrateMetadataRef < ' a > {
189
190
fn raw_bytes ( self ) -> & ' a [ u8 ] {
190
191
self . blob . raw_bytes ( )
191
192
}
192
- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
193
- Some ( self )
193
+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
194
+ Some ( * self )
194
195
}
195
196
}
196
197
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 ) {
198
199
fn raw_bytes ( self ) -> & ' a [ u8 ] {
199
200
self . 0 . raw_bytes ( )
200
201
}
201
- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
202
- Some ( self . 0 )
202
+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
203
+ Some ( * self . 0 )
203
204
}
204
205
fn sess ( self ) -> Option < & ' tcx Session > {
205
206
Some ( & self . 1 )
206
207
}
207
208
}
208
209
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 > ) {
210
211
fn raw_bytes ( self ) -> & ' a [ u8 ] {
211
212
self . 0 . raw_bytes ( )
212
213
}
213
- fn cdata ( self ) -> Option < & ' a CrateMetadata > {
214
- Some ( self . 0 )
214
+ fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
215
+ Some ( * self . 0 )
215
216
}
216
217
fn tcx ( self ) -> Option < TyCtxt < ' tcx > > {
217
218
Some ( self . 1 )
@@ -242,7 +243,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
242
243
self . tcx . expect ( "missing TyCtxt in DecodeContext" )
243
244
}
244
245
245
- fn cdata ( & self ) -> & ' a CrateMetadata {
246
+ fn cdata ( & self ) -> CrateMetadataRef < ' a > {
246
247
self . cdata . expect ( "missing CrateMetadata in DecodeContext" )
247
248
}
248
249
@@ -558,7 +559,7 @@ impl CrateRoot<'_> {
558
559
}
559
560
}
560
561
561
- impl < ' a , ' tcx > CrateMetadata {
562
+ impl CrateMetadata {
562
563
crate fn new (
563
564
sess : & Session ,
564
565
blob : MetadataBlob ,
@@ -601,7 +602,9 @@ impl<'a, 'tcx> CrateMetadata {
601
602
extern_crate : Lock :: new ( None ) ,
602
603
}
603
604
}
605
+ }
604
606
607
+ impl < ' a , ' tcx > CrateMetadataRef < ' a > {
605
608
fn is_proc_macro ( & self , id : DefIndex ) -> bool {
606
609
self . root . proc_macro_data . and_then ( |data| data. decode ( self ) . find ( |x| * x == id) ) . is_some ( )
607
610
}
@@ -1440,10 +1443,10 @@ impl<'a, 'tcx> CrateMetadata {
1440
1443
/// Proc macro crates don't currently export spans, so this function does not have
1441
1444
/// to work for them.
1442
1445
fn imported_source_files (
1443
- & ' a self ,
1446
+ & self ,
1444
1447
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 ( || {
1447
1450
let external_source_map = self . root . source_map . decode ( self ) ;
1448
1451
1449
1452
external_source_map
@@ -1540,7 +1543,9 @@ impl<'a, 'tcx> CrateMetadata {
1540
1543
1541
1544
dep_node_index
1542
1545
}
1546
+ }
1543
1547
1548
+ impl CrateMetadata {
1544
1549
crate fn dependencies ( & self ) -> LockGuard < ' _ , Vec < CrateNum > > {
1545
1550
self . dependencies . borrow ( )
1546
1551
}
0 commit comments