@@ -214,12 +214,12 @@ impl<'a> LazyDecoder for BlobDecodeContext<'a> {
214214/// Decoding of some types, like `Span` require some information to already been read.
215215pub ( super ) struct MetadataDecodeContext < ' a , ' tcx > {
216216 blob_decoder : BlobDecodeContext < ' a > ,
217- cdata : Option < CrateMetadataRef < ' a > > ,
217+ cdata : CrateMetadataRef < ' a > ,
218218 sess : Option < & ' tcx Session > ,
219219 tcx : Option < TyCtxt < ' tcx > > ,
220220
221221 // Used for decoding interpret::AllocIds in a cached & thread-safe manner.
222- alloc_decoding_session : Option < AllocDecodingSession < ' a > > ,
222+ alloc_decoding_session : AllocDecodingSession < ' a > ,
223223}
224224
225225impl < ' a , ' tcx > LazyDecoder for MetadataDecodeContext < ' a , ' tcx > {
@@ -257,9 +257,7 @@ pub(super) trait BlobMetadata<'a, 'tcx>: Copy {
257257pub ( super ) trait Metadata < ' a , ' tcx > : Copy {
258258 fn _blob ( self ) -> & ' a MetadataBlob ;
259259
260- fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
261- None
262- }
260+ fn cdata ( self ) -> CrateMetadataRef < ' a > ;
263261 fn sess ( self ) -> Option < & ' tcx Session > {
264262 None
265263 }
@@ -280,14 +278,13 @@ where
280278
281279 fn decoder ( self , pos : usize ) -> MetadataDecodeContext < ' a , ' tcx > {
282280 let tcx = self . tcx ( ) ;
281+ let cdata = self . cdata ( ) ;
283282 MetadataDecodeContext {
284283 blob_decoder : self . blob ( ) . decoder ( pos) ,
285- cdata : self . cdata ( ) ,
284+ cdata,
286285 sess : self . sess ( ) . or ( tcx. map ( |tcx| tcx. sess ) ) ,
287286 tcx,
288- alloc_decoding_session : self
289- . cdata ( )
290- . map ( |cdata| cdata. cdata . alloc_decoding_state . new_decoding_session ( ) ) ,
287+ alloc_decoding_session : cdata. cdata . alloc_decoding_state . new_decoding_session ( ) ,
291288 }
292289 }
293290}
@@ -321,8 +318,8 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for CrateMetadataRef<'a> {
321318 & self . cdata . blob
322319 }
323320 #[ inline]
324- fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
325- Some ( self )
321+ fn cdata ( self ) -> CrateMetadataRef < ' a > {
322+ self
326323 }
327324}
328325
@@ -332,8 +329,8 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, &'tcx Session) {
332329 & self . 0 . cdata . blob
333330 }
334331 #[ inline]
335- fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
336- Some ( self . 0 )
332+ fn cdata ( self ) -> CrateMetadataRef < ' a > {
333+ self . 0
337334 }
338335 #[ inline]
339336 fn sess ( self ) -> Option < & ' tcx Session > {
@@ -347,8 +344,8 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
347344 & self . 0 . cdata . blob
348345 }
349346 #[ inline]
350- fn cdata ( self ) -> Option < CrateMetadataRef < ' a > > {
351- Some ( self . 0 )
347+ fn cdata ( self ) -> CrateMetadataRef < ' a > {
348+ self . 0
352349 }
353350 #[ inline]
354351 fn tcx ( self ) -> Option < TyCtxt < ' tcx > > {
@@ -423,15 +420,9 @@ impl<'a, 'tcx> MetadataDecodeContext<'a, 'tcx> {
423420 tcx
424421 }
425422
426- #[ inline]
427- fn cdata ( & self ) -> CrateMetadataRef < ' a > {
428- debug_assert ! ( self . cdata. is_some( ) , "missing CrateMetadata in DecodeContext" ) ;
429- self . cdata . unwrap ( )
430- }
431-
432423 #[ inline]
433424 fn map_encoded_cnum_to_current ( & self , cnum : CrateNum ) -> CrateNum {
434- self . cdata ( ) . map_encoded_cnum_to_current ( cnum)
425+ self . cdata . map_encoded_cnum_to_current ( cnum)
435426 }
436427}
437428
@@ -483,7 +474,7 @@ impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> {
483474 {
484475 let tcx = self . tcx ( ) ;
485476
486- let key = ty:: CReaderCacheKey { cnum : Some ( self . cdata ( ) . cnum ) , pos : shorthand } ;
477+ let key = ty:: CReaderCacheKey { cnum : Some ( self . cdata . cnum ) , pos : shorthand } ;
487478
488479 if let Some ( & ty) = tcx. ty_rcache . borrow ( ) . get ( & key) {
489480 return ty;
@@ -508,11 +499,8 @@ impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> {
508499 }
509500
510501 fn decode_alloc_id ( & mut self ) -> rustc_middle:: mir:: interpret:: AllocId {
511- if let Some ( alloc_decoding_session) = self . alloc_decoding_session {
512- alloc_decoding_session. decode_alloc_id ( self )
513- } else {
514- bug ! ( "Attempting to decode interpret::AllocId without CrateMetadata" )
515- }
502+ let ads = self . alloc_decoding_session ;
503+ ads. decode_alloc_id ( self )
516504 }
517505}
518506
@@ -539,8 +527,7 @@ impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
539527 }
540528
541529 fn decode_syntax_context ( & mut self ) -> SyntaxContext {
542- let cdata = self . cdata ( ) ;
543-
530+ let cdata = self . cdata ;
544531 let Some ( sess) = self . sess else {
545532 bug ! (
546533 "Cannot decode SyntaxContext without Session.\
@@ -561,7 +548,7 @@ impl<'a, 'tcx> SpanDecoder for MetadataDecodeContext<'a, 'tcx> {
561548 }
562549
563550 fn decode_expn_id ( & mut self ) -> ExpnId {
564- let local_cdata = self . cdata ( ) ;
551+ let local_cdata = self . cdata ;
565552
566553 let Some ( sess) = self . sess else {
567554 bug ! (
@@ -712,18 +699,17 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for SpanData {
712699 // we can call `imported_source_file` for the proper crate, and binary search
713700 // through the returned slice using our span.
714701 let source_file = if tag. kind ( ) == SpanKind :: Local {
715- decoder. cdata ( ) . imported_source_file ( metadata_index, sess)
702+ decoder. cdata . imported_source_file ( metadata_index, sess)
716703 } else {
717704 // When we encode a proc-macro crate, all `Span`s should be encoded
718705 // with `TAG_VALID_SPAN_LOCAL`
719- if decoder. cdata ( ) . root . is_proc_macro_crate ( ) {
706+ if decoder. cdata . root . is_proc_macro_crate ( ) {
720707 // Decode `CrateNum` as u32 - using `CrateNum::decode` will ICE
721708 // since we don't have `cnum_map` populated.
722709 let cnum = u32:: decode ( decoder) ;
723710 panic ! (
724711 "Decoding of crate {:?} tried to access proc-macro dep {:?}" ,
725- decoder. cdata( ) . root. header. name,
726- cnum
712+ decoder. cdata. root. header. name, cnum
727713 ) ;
728714 }
729715 // tag is TAG_VALID_SPAN_FOREIGN, checked by `debug_assert` above
@@ -733,7 +719,7 @@ impl<'a, 'tcx> Decodable<MetadataDecodeContext<'a, 'tcx>> for SpanData {
733719 cnum
734720 ) ;
735721
736- let foreign_data = decoder. cdata ( ) . cstore . get_crate_data ( cnum) ;
722+ let foreign_data = decoder. cdata . cstore . get_crate_data ( cnum) ;
737723 foreign_data. imported_source_file ( metadata_index, sess)
738724 } ;
739725
0 commit comments