@@ -311,8 +311,11 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
311311impl < ' a , ' tcx > DecodeContext < ' a , ' tcx > {
312312 #[ inline]
313313 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
316319 }
317320
318321 #[ inline]
@@ -454,7 +457,12 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
454457impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for SyntaxContext {
455458 fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> SyntaxContext {
456459 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+
458466 let cname = cdata. root . name ;
459467 rustc_span:: hygiene:: decode_syntax_context ( decoder, & cdata. hygiene_context , |_, id| {
460468 debug ! ( "SpecializedDecoder<SyntaxContext>: decoding {}" , id) ;
@@ -471,7 +479,11 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
471479impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for ExpnId {
472480 fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> ExpnId {
473481 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+ } ;
475487
476488 let cnum = CrateNum :: decode ( decoder) ;
477489 let index = u32:: decode ( decoder) ;
@@ -520,7 +532,8 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
520532 let hi = lo + len;
521533
522534 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`.")
524537 } ;
525538
526539 // Index of the file in the corresponding crate's list of encoded files.
0 commit comments