@@ -2660,12 +2660,12 @@ where
2660
2660
}
2661
2661
2662
2662
if let Some ( parent) = span. parent {
2663
- let def_span = ctx. def_span ( parent) . data_untracked ( ) ;
2664
- if def_span . contains ( span) {
2663
+ let parent_span = ctx. def_span ( parent) . data_untracked ( ) ;
2664
+ if parent_span . contains ( span) {
2665
2665
// This span is enclosed in a definition: only hash the relative position.
2666
2666
Hash :: hash ( & TAG_RELATIVE_SPAN , hasher) ;
2667
- ( span. lo - def_span . lo ) . to_u32 ( ) . hash_stable ( ctx , hasher) ;
2668
- ( span. hi - def_span . lo ) . to_u32 ( ) . hash_stable ( ctx , hasher) ;
2667
+ Hash :: hash ( & ( span. lo - parent_span . lo ) , hasher) ;
2668
+ Hash :: hash ( & ( span. hi - parent_span . lo ) , hasher) ;
2669
2669
return ;
2670
2670
}
2671
2671
}
@@ -2682,6 +2682,25 @@ where
2682
2682
Hash :: hash ( & TAG_VALID_SPAN , hasher) ;
2683
2683
Hash :: hash ( & file, hasher) ;
2684
2684
2685
+ if let Some ( parent) = span. parent {
2686
+ let parent_span = ctx. def_span ( parent) . data_untracked ( ) ;
2687
+ let Some ( ( parent_file, ..) ) = ctx. span_data_to_lines_and_cols ( & parent_span) else {
2688
+ Hash :: hash ( & TAG_INVALID_SPAN , hasher) ;
2689
+ return ;
2690
+ } ;
2691
+
2692
+ if parent_file == file {
2693
+ // This span is relative to another span in the same file,
2694
+ // only hash the relative position.
2695
+ Hash :: hash ( & TAG_RELATIVE_SPAN , hasher) ;
2696
+ // Use signed difference as `span` may start before `parent_span`,
2697
+ // for instance attributes start before their item's span.
2698
+ Hash :: hash ( & ( span. lo . to_u32 ( ) as isize - parent_span. lo . to_u32 ( ) as isize ) , hasher) ;
2699
+ Hash :: hash ( & ( span. hi . to_u32 ( ) as isize - parent_span. lo . to_u32 ( ) as isize ) , hasher) ;
2700
+ return ;
2701
+ }
2702
+ }
2703
+
2685
2704
// Hash both the length and the end location (line/column) of a span. If we
2686
2705
// hash only the length, for example, then two otherwise equal spans with
2687
2706
// different end locations will have the same hash. This can cause a problem
0 commit comments