@@ -20,8 +20,8 @@ use rustc_span::hygiene::{
2020} ;
2121use rustc_span:: source_map:: Spanned ;
2222use rustc_span:: {
23- BlobDecoder , BytePos , ByteSymbol , CachingSourceMapView , ExpnData , ExpnHash , Pos ,
24- RelativeBytePos , SourceFile , Span , SpanDecoder , SpanEncoder , StableSourceFileId , Symbol ,
23+ BlobDecoder , BytePos , ByteSymbol , CachingSourceMapView , ExpnData , ExpnHash , RelativeBytePos ,
24+ SourceFile , Span , SpanDecoder , SpanEncoder , StableSourceFileId , Symbol ,
2525} ;
2626
2727use crate :: dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
@@ -652,7 +652,10 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
652652 let dto = u32:: decode ( self ) ;
653653
654654 let enclosing = self . tcx . source_span_untracked ( parent. unwrap ( ) ) . data_untracked ( ) ;
655- ( enclosing. lo + BytePos :: from_u32 ( dlo) , enclosing. lo + BytePos :: from_u32 ( dto) )
655+ (
656+ BytePos ( enclosing. lo . 0 . wrapping_add ( dlo) ) ,
657+ BytePos ( enclosing. lo . 0 . wrapping_add ( dto) ) ,
658+ )
656659 }
657660 TAG_FULL_SPAN => {
658661 let file_lo_index = SourceFileIndex :: decode ( self ) ;
@@ -894,28 +897,23 @@ impl<'a, 'tcx> SpanEncoder for CacheEncoder<'a, 'tcx> {
894897 return TAG_PARTIAL_SPAN . encode ( self ) ;
895898 }
896899
897- if let Some ( parent) = span_data. parent {
898- let enclosing = self . tcx . source_span_untracked ( parent) . data_untracked ( ) ;
899- if enclosing. contains ( span_data) {
900- TAG_RELATIVE_SPAN . encode ( self ) ;
901- ( span_data. lo - enclosing. lo ) . to_u32 ( ) . encode ( self ) ;
902- ( span_data. hi - enclosing. lo ) . to_u32 ( ) . encode ( self ) ;
903- return ;
904- }
905- }
906-
907- let pos = self . source_map . byte_pos_to_line_and_col ( span_data. lo ) ;
908- let partial_span = match & pos {
909- Some ( ( file_lo, _, _) ) => !file_lo. contains ( span_data. hi ) ,
910- None => true ,
900+ let parent =
901+ span_data. parent . map ( |parent| self . tcx . source_span_untracked ( parent) . data_untracked ( ) ) ;
902+ let Some ( ( file_lo, line_lo, col_lo) ) =
903+ self . source_map . byte_pos_to_line_and_col ( span_data. lo )
904+ else {
905+ return TAG_PARTIAL_SPAN . encode ( self ) ;
911906 } ;
912907
913- if partial_span {
914- return TAG_PARTIAL_SPAN . encode ( self ) ;
908+ if let Some ( parent) = parent
909+ && file_lo. contains ( parent. lo )
910+ {
911+ TAG_RELATIVE_SPAN . encode ( self ) ;
912+ ( span_data. lo . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
913+ ( span_data. hi . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
914+ return ;
915915 }
916916
917- let ( file_lo, line_lo, col_lo) = pos. unwrap ( ) ;
918-
919917 let len = span_data. hi - span_data. lo ;
920918
921919 let source_file_index = self . source_file_index ( file_lo) ;
0 commit comments