@@ -409,21 +409,6 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
409
409
}
410
410
}
411
411
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
-
427
412
impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for ExpnIndex {
428
413
#[ inline]
429
414
fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> ExpnIndex {
@@ -439,19 +424,32 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
439
424
}
440
425
}
441
426
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
+ }
445
432
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 {
447
445
bug ! (
448
446
"Cannot decode SyntaxContext without Session.\
449
447
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
450
448
) ;
451
449
} ;
452
450
453
451
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| {
455
453
debug ! ( "SpecializedDecoder<SyntaxContext>: decoding {}" , id) ;
456
454
cdata
457
455
. root
@@ -461,21 +459,19 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
461
459
. decode ( ( cdata, sess) )
462
460
} )
463
461
}
464
- }
465
462
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 ( ) ;
469
465
470
- let Some ( sess) = decoder . sess else {
466
+ let Some ( sess) = self . sess else {
471
467
bug ! (
472
468
"Cannot decode ExpnId without Session. \
473
469
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`."
474
470
) ;
475
471
} ;
476
472
477
- let cnum = CrateNum :: decode ( decoder ) ;
478
- let index = u32:: decode ( decoder ) ;
473
+ let cnum = CrateNum :: decode ( self ) ;
474
+ let index = u32:: decode ( self ) ;
479
475
480
476
let expn_id = rustc_span:: hygiene:: decode_expn_id ( cnum, index, |expn_id| {
481
477
let ExpnId { krate : cnum, local_id : index } = expn_id;
@@ -503,9 +499,7 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
503
499
} ) ;
504
500
expn_id
505
501
}
506
- }
507
502
508
- impl < ' a , ' tcx > SpanDecoder for DecodeContext < ' a , ' tcx > {
509
503
fn decode_span ( & mut self ) -> Span {
510
504
let start = self . position ( ) ;
511
505
let tag = SpanTag ( self . peek_byte ( ) ) ;
@@ -524,6 +518,32 @@ impl<'a, 'tcx> SpanDecoder for DecodeContext<'a, 'tcx> {
524
518
} ;
525
519
Span :: new ( data. lo , data. hi , data. ctxt , data. parent )
526
520
}
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
+ }
527
547
}
528
548
529
549
impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for SpanData {
@@ -631,34 +651,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SpanData {
631
651
}
632
652
}
633
653
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
-
662
654
impl < ' a , ' tcx > Decodable < DecodeContext < ' a , ' tcx > > for & ' tcx [ ( ty:: Clause < ' tcx > , Span ) ] {
663
655
fn decode ( d : & mut DecodeContext < ' a , ' tcx > ) -> Self {
664
656
ty:: codec:: RefDecodable :: decode ( d)
0 commit comments