@@ -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,30 +897,33 @@ 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- }
900+ let parent =
901+ span_data. parent . map ( |parent| self . tcx . source_span_untracked ( parent) . data_untracked ( ) ) ;
902+ if let Some ( parent) = parent
903+ && parent. contains ( span_data)
904+ {
905+ TAG_RELATIVE_SPAN . encode ( self ) ;
906+ ( span_data. lo . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
907+ ( span_data. hi . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
908+ return ;
905909 }
906910
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 ,
911+ let Some ( ( file_lo , line_lo , col_lo ) ) =
912+ self . source_map . byte_pos_to_line_and_col ( span_data . lo )
913+ else {
914+ return TAG_PARTIAL_SPAN . encode ( self ) ;
911915 } ;
912916
913- if partial_span {
914- return TAG_PARTIAL_SPAN . encode ( self ) ;
917+ if let Some ( parent) = parent
918+ && file_lo. contains ( parent. lo )
919+ {
920+ TAG_RELATIVE_SPAN . encode ( self ) ;
921+ ( span_data. lo . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
922+ ( span_data. hi . 0 . wrapping_sub ( parent. lo . 0 ) ) . encode ( self ) ;
923+ return ;
915924 }
916925
917- let ( file_lo, line_lo, col_lo) = pos. unwrap ( ) ;
918-
919926 let len = span_data. hi - span_data. lo ;
920-
921927 let source_file_index = self . source_file_index ( file_lo) ;
922928
923929 TAG_FULL_SPAN . encode ( self ) ;
0 commit comments