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