@@ -409,21 +409,6 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
409409 }
410410}
411411
412- impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for CrateNum {
413- #[ inline]
414- fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> CrateNum {
415- let cnum = CrateNum :: from_u32 ( d. read_u32 ( ) ) ;
416- d. map_encoded_cnum_to_current ( cnum)
417- }
418- }
419-
420- impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for DefIndex {
421- #[ inline]
422- fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> DefIndex {
423- DefIndex :: from_u32 ( d. read_u32 ( ) )
424- }
425- }
426-
427412impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for ExpnIndex {
428413 #[ inline]
429414 fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> ExpnIndex {
@@ -439,19 +424,32 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
439424 }
440425}
441426
442- impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for SyntaxContext {
443- fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> SyntaxContext {
444- let cdata = decoder. cdata ( ) ;
427+ impl < ' a , ' tcx > SpanDecoder for DecodeContext < ' a , ' tcx > {
428+ fn decode_crate_num ( & mut self ) -> CrateNum {
429+ let cnum = CrateNum :: from_u32 ( self . read_u32 ( ) ) ;
430+ self . map_encoded_cnum_to_current ( cnum)
431+ }
445432
446- let Some ( sess) = decoder. sess else {
433+ fn decode_def_index ( & mut self ) -> DefIndex {
434+ DefIndex :: from_u32 ( self . read_u32 ( ) )
435+ }
436+
437+ fn decode_def_id ( & mut self ) -> DefId {
438+ DefId { krate : Decodable :: decode ( self ) , index : Decodable :: decode ( self ) }
439+ }
440+
441+ fn decode_syntax_context ( & mut self ) -> SyntaxContext {
442+ let cdata = self . cdata ( ) ;
443+
444+ let Some ( sess) = self . sess else {
447445 bug ! (
448446 "Cannot decode SyntaxContext without Session.\
449447 You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
450448 ) ;
451449 } ;
452450
453451 let cname = cdata. root . name ( ) ;
454- rustc_span:: hygiene:: decode_syntax_context ( decoder , & cdata. hygiene_context , |_, id| {
452+ rustc_span:: hygiene:: decode_syntax_context ( self , & cdata. hygiene_context , |_, id| {
455453 debug ! ( "SpecializedDecoder<SyntaxContext>: decoding {}" , id) ;
456454 cdata
457455 . root
@@ -461,21 +459,19 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
461459 . decode ( ( cdata, sess) )
462460 } )
463461 }
464- }
465462
466- impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for ExpnId {
467- fn decode ( decoder : & mut DecodeContext < ' a , ' tcx > ) -> ExpnId {
468- let local_cdata = decoder. cdata ( ) ;
463+ fn decode_expn_id ( & mut self ) -> ExpnId {
464+ let local_cdata = self . cdata ( ) ;
469465
470- let Some ( sess) = decoder . sess else {
466+ let Some ( sess) = self . sess else {
471467 bug ! (
472468 "Cannot decode ExpnId without Session. \
473469 You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
474470 ) ;
475471 } ;
476472
477- let cnum = CrateNum :: decode ( decoder ) ;
478- let index = u32:: decode ( decoder ) ;
473+ let cnum = CrateNum :: decode ( self ) ;
474+ let index = u32:: decode ( self ) ;
479475
480476 let expn_id = rustc_span:: hygiene:: decode_expn_id ( cnum, index, |expn_id| {
481477 let ExpnId { krate : cnum, local_id : index } = expn_id;
@@ -503,9 +499,7 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
503499 } ) ;
504500 expn_id
505501 }
506- }
507502
508- impl < ' a , ' tcx > SpanDecoder for DecodeContext < ' a , ' tcx > {
509503 fn decode_span ( & mut self ) -> Span {
510504 let start = self . position ( ) ;
511505 let tag = SpanTag ( self . peek_byte ( ) ) ;
@@ -524,6 +518,32 @@ impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
524518 } ;
525519 Span :: new ( data. lo , data. hi , data. ctxt , data. parent )
526520 }
521+
522+ fn decode_symbol ( & mut self ) -> Symbol {
523+ let tag = self . read_u8 ( ) ;
524+
525+ match tag {
526+ SYMBOL_STR => {
527+ let s = self . read_str ( ) ;
528+ Symbol :: intern ( s)
529+ }
530+ SYMBOL_OFFSET => {
531+ // read str offset
532+ let pos = self . read_usize ( ) ;
533+
534+ // move to str offset and read
535+ self . opaque . with_position ( pos, |d| {
536+ let s = d. read_str ( ) ;
537+ Symbol :: intern ( s)
538+ } )
539+ }
540+ SYMBOL_PREINTERNED => {
541+ let symbol_index = self . read_u32 ( ) ;
542+ Symbol :: new_from_decoded ( symbol_index)
543+ }
544+ _ => unreachable ! ( ) ,
545+ }
546+ }
527547}
528548
529549impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for SpanData {
@@ -631,34 +651,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SpanData {
631651 }
632652}
633653
634- impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for Symbol {
635- fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> Self {
636- let tag = d. read_u8 ( ) ;
637-
638- match tag {
639- SYMBOL_STR => {
640- let s = d. read_str ( ) ;
641- Symbol :: intern ( s)
642- }
643- SYMBOL_OFFSET => {
644- // read str offset
645- let pos = d. read_usize ( ) ;
646-
647- // move to str offset and read
648- d. opaque . with_position ( pos, |d| {
649- let s = d. read_str ( ) ;
650- Symbol :: intern ( s)
651- } )
652- }
653- SYMBOL_PREINTERNED => {
654- let symbol_index = d. read_u32 ( ) ;
655- Symbol :: new_from_decoded ( symbol_index)
656- }
657- _ => unreachable ! ( ) ,
658- }
659- }
660- }
661-
662654impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for & ' tcx [ ( ty:: Clause < ' tcx > , Span ) ] {
663655 fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> Self {
664656 ty:: codec:: RefDecodable :: decode ( d)
0 commit comments