@@ -169,13 +169,12 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
169169
170170 // Decode the *position* of the footer, which can be found in the
171171 // last 8 bytes of the file.
172- decoder. set_position ( data. len ( ) - IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
173- let footer_pos = IntEncodedWithFixedSize :: decode ( & mut decoder) . 0 as usize ;
174-
172+ let footer_pos = decoder
173+ . with_position ( decoder. len ( ) - IntEncodedWithFixedSize :: ENCODED_SIZE , |decoder| {
174+ IntEncodedWithFixedSize :: decode ( decoder) . 0 as usize
175+ } ) ;
175176 // Decode the file footer, which contains all the lookup tables, etc.
176- decoder. set_position ( footer_pos) ;
177-
178- decode_tagged ( & mut decoder, TAG_FILE_FOOTER )
177+ decoder. with_position ( footer_pos, |decoder| decode_tagged ( decoder, TAG_FILE_FOOTER ) )
179178 } ;
180179
181180 Self {
@@ -522,29 +521,13 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
522521 }
523522}
524523
525- trait DecoderWithPosition : Decoder {
526- fn position ( & self ) -> usize ;
527- }
528-
529- impl < ' a > DecoderWithPosition for MemDecoder < ' a > {
530- fn position ( & self ) -> usize {
531- self . position ( )
532- }
533- }
534-
535- impl < ' a , ' tcx > DecoderWithPosition for CacheDecoder < ' a , ' tcx > {
536- fn position ( & self ) -> usize {
537- self . opaque . position ( )
538- }
539- }
540-
541524// Decodes something that was encoded with `encode_tagged()` and verify that the
542525// tag matches and the correct amount of bytes was read.
543526fn decode_tagged < D , T , V > ( decoder : & mut D , expected_tag : T ) -> V
544527where
545528 T : Decodable < D > + Eq + std:: fmt:: Debug ,
546529 V : Decodable < D > ,
547- D : DecoderWithPosition ,
530+ D : Decoder ,
548531{
549532 let start_pos = decoder. position ( ) ;
550533
@@ -568,16 +551,6 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
568551 self . tcx
569552 }
570553
571- #[ inline]
572- fn position ( & self ) -> usize {
573- self . opaque . position ( )
574- }
575-
576- #[ inline]
577- fn peek_byte ( & self ) -> u8 {
578- self . opaque . data [ self . opaque . position ( ) ]
579- }
580-
581554 fn cached_ty_for_shorthand < F > ( & mut self , shorthand : usize , or_insert_with : F ) -> Ty < ' tcx >
582555 where
583556 F : FnOnce ( & mut Self ) -> Ty < ' tcx > ,
@@ -600,9 +573,9 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
600573 where
601574 F : FnOnce ( & mut Self ) -> R ,
602575 {
603- debug_assert ! ( pos < self . opaque. data . len( ) ) ;
576+ debug_assert ! ( pos < self . opaque. len( ) ) ;
604577
605- let new_opaque = MemDecoder :: new ( self . opaque . data , pos) ;
578+ let new_opaque = MemDecoder :: new ( self . opaque . data ( ) , pos) ;
606579 let old_opaque = mem:: replace ( & mut self . opaque , new_opaque) ;
607580 let r = f ( self ) ;
608581 self . opaque = old_opaque;
@@ -743,17 +716,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Symbol {
743716 SYMBOL_OFFSET => {
744717 // read str offset
745718 let pos = d. read_usize ( ) ;
746- let old_pos = d. opaque . position ( ) ;
747719
748720 // move to str offset and read
749- d. opaque . set_position ( pos) ;
750- let s = d. read_str ( ) ;
751- let sym = Symbol :: intern ( s) ;
752-
753- // restore position
754- d. opaque . set_position ( old_pos) ;
755-
756- sym
721+ d. opaque . with_position ( pos, |d| {
722+ let s = d. read_str ( ) ;
723+ Symbol :: intern ( s)
724+ } )
757725 }
758726 SYMBOL_PREINTERNED => {
759727 let symbol_index = d. read_u32 ( ) ;
0 commit comments