@@ -311,8 +311,11 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
311
311
impl < ' a , ' tcx > DecodeContext < ' a , ' tcx > {
312
312
#[ inline]
313
313
fn tcx ( & self ) -> TyCtxt < ' tcx > {
314
- debug_assert ! ( self . tcx. is_some( ) , "missing TyCtxt in DecodeContext" ) ;
315
- self . tcx . unwrap ( )
314
+ let Some ( tcx) = self . tcx else {
315
+ bug ! ( "No TyCtxt found for decoding. \
316
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.") ;
317
+ } ;
318
+ tcx
316
319
}
317
320
318
321
#[ inline]
@@ -454,7 +457,12 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
454
457
impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for SyntaxContext {
455
458
fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> SyntaxContext {
456
459
let cdata = decoder. cdata ( ) ;
457
- let sess = decoder. sess . unwrap ( ) ;
460
+
461
+ let Some ( sess) = decoder. sess else {
462
+ bug ! ( "Cannot decode SyntaxContext without Session.\
463
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.") ;
464
+ } ;
465
+
458
466
let cname = cdata. root . name ;
459
467
rustc_span:: hygiene:: decode_syntax_context ( decoder, & cdata. hygiene_context , |_, id| {
460
468
debug ! ( "SpecializedDecoder<SyntaxContext>: decoding {}" , id) ;
@@ -471,7 +479,11 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
471
479
impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for ExpnId {
472
480
fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> ExpnId {
473
481
let local_cdata = decoder. cdata ( ) ;
474
- let sess = decoder. sess . unwrap ( ) ;
482
+
483
+ let Some ( sess) = decoder. sess else {
484
+ bug ! ( "Cannot decode ExpnId without Session. \
485
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.") ;
486
+ } ;
475
487
476
488
let cnum = CrateNum :: decode ( decoder) ;
477
489
let index = u32:: decode ( decoder) ;
@@ -520,7 +532,8 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
520
532
let hi = lo + len;
521
533
522
534
let Some ( sess) = decoder. sess else {
523
- bug ! ( "Cannot decode Span without Session." )
535
+ bug ! ( "Cannot decode Span without Session. \
536
+ You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.")
524
537
} ;
525
538
526
539
// Index of the file in the corresponding crate's list of encoded files.
0 commit comments