@@ -2671,12 +2671,12 @@ where
2671
2671
}
2672
2672
2673
2673
if let Some ( parent) = span. parent {
2674
- let def_span = ctx. def_span ( parent) . data_untracked ( ) ;
2675
- if def_span . contains ( span) {
2674
+ let parent_span = ctx. def_span ( parent) . data_untracked ( ) ;
2675
+ if parent_span . contains ( span) {
2676
2676
// This span is enclosed in a definition: only hash the relative position.
2677
2677
Hash :: hash ( & TAG_RELATIVE_SPAN , hasher) ;
2678
- ( span. lo - def_span . lo ) . to_u32 ( ) . hash_stable ( ctx , hasher) ;
2679
- ( span. hi - def_span . lo ) . to_u32 ( ) . hash_stable ( ctx , hasher) ;
2678
+ Hash :: hash ( & ( span. lo - parent_span . lo ) , hasher) ;
2679
+ Hash :: hash ( & ( span. hi - parent_span . lo ) , hasher) ;
2680
2680
return ;
2681
2681
}
2682
2682
}
@@ -2693,6 +2693,25 @@ where
2693
2693
Hash :: hash ( & TAG_VALID_SPAN , hasher) ;
2694
2694
Hash :: hash ( & file, hasher) ;
2695
2695
2696
+ if let Some ( parent) = span. parent {
2697
+ let parent_span = ctx. def_span ( parent) . data_untracked ( ) ;
2698
+ let Some ( ( parent_file, ..) ) = ctx. span_data_to_lines_and_cols ( & parent_span) else {
2699
+ Hash :: hash ( & TAG_INVALID_SPAN , hasher) ;
2700
+ return ;
2701
+ } ;
2702
+
2703
+ if parent_file == file {
2704
+ // This span is relative to another span in the same file,
2705
+ // only hash the relative position.
2706
+ Hash :: hash ( & TAG_RELATIVE_SPAN , hasher) ;
2707
+ // Use signed difference as `span` may start before `parent_span`,
2708
+ // for instance attributes start before their item's span.
2709
+ Hash :: hash ( & ( span. lo . to_u32 ( ) as isize - parent_span. lo . to_u32 ( ) as isize ) , hasher) ;
2710
+ Hash :: hash ( & ( span. hi . to_u32 ( ) as isize - parent_span. lo . to_u32 ( ) as isize ) , hasher) ;
2711
+ return ;
2712
+ }
2713
+ }
2714
+
2696
2715
// Hash both the length and the end ___location (line/column) of a span. If we
2697
2716
// hash only the length, for example, then two otherwise equal spans with
2698
2717
// different end locations will have the same hash. This can cause a problem
0 commit comments