@@ -2671,12 +2671,12 @@ where
26712671 }
26722672
26732673 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) {
26762676 // This span is enclosed in a definition: only hash the relative position.
26772677 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) ;
26802680 return ;
26812681 }
26822682 }
@@ -2693,6 +2693,25 @@ where
26932693 Hash :: hash ( & TAG_VALID_SPAN , hasher) ;
26942694 Hash :: hash ( & file, hasher) ;
26952695
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+
26962715 // Hash both the length and the end location (line/column) of a span. If we
26972716 // hash only the length, for example, then two otherwise equal spans with
26982717 // different end locations will have the same hash. This can cause a problem
0 commit comments