@@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
48
48
use rustc_errors:: { struct_span_err, Applicability } ;
49
49
use rustc_hir as hir;
50
50
use rustc_hir:: def:: { DefKind , Namespace , PartialRes , PerNS , Res } ;
51
- use rustc_hir:: def_id:: { DefId , DefIdMap , LocalDefId , CRATE_DEF_ID } ;
51
+ use rustc_hir:: def_id:: { DefId , DefIdMap , DefPathHash , LocalDefId , CRATE_DEF_ID } ;
52
52
use rustc_hir:: definitions:: { DefKey , DefPathData , Definitions } ;
53
53
use rustc_hir:: intravisit;
54
54
use rustc_hir:: { ConstArg , GenericArg , ParamName } ;
@@ -59,7 +59,7 @@ use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
59
59
use rustc_session:: Session ;
60
60
use rustc_span:: edition:: Edition ;
61
61
use rustc_span:: hygiene:: ExpnId ;
62
- use rustc_span:: source_map:: { respan, DesugaringKind } ;
62
+ use rustc_span:: source_map:: { respan, CachingSourceMapView , DesugaringKind } ;
63
63
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
64
64
use rustc_span:: { Span , DUMMY_SP } ;
65
65
use rustc_target:: spec:: abi:: Abi ;
@@ -204,6 +204,8 @@ pub trait ResolverAstLowering {
204
204
205
205
fn local_def_id ( & self , node : NodeId ) -> LocalDefId ;
206
206
207
+ fn def_path_hash ( & self , def_id : DefId ) -> DefPathHash ;
208
+
207
209
fn create_def (
208
210
& mut self ,
209
211
parent : LocalDefId ,
@@ -214,6 +216,32 @@ pub trait ResolverAstLowering {
214
216
) -> LocalDefId ;
215
217
}
216
218
219
+ struct LoweringHasher < ' a > {
220
+ source_map : CachingSourceMapView < ' a > ,
221
+ resolver : & ' a dyn ResolverAstLowering ,
222
+ }
223
+
224
+ impl < ' a > rustc_span:: HashStableContext for LoweringHasher < ' a > {
225
+ #[ inline]
226
+ fn hash_spans ( & self ) -> bool {
227
+ true
228
+ }
229
+
230
+ #[ inline]
231
+ fn def_path_hash ( & self , def_id : DefId ) -> DefPathHash {
232
+ self . resolver . def_path_hash ( def_id)
233
+ }
234
+
235
+ #[ inline]
236
+ fn span_data_to_lines_and_cols (
237
+ & mut self ,
238
+ span : & rustc_span:: SpanData ,
239
+ ) -> Option < ( Lrc < rustc_span:: SourceFile > , usize , rustc_span:: BytePos , usize , rustc_span:: BytePos ) >
240
+ {
241
+ self . source_map . span_data_to_lines_and_cols ( span)
242
+ }
243
+ }
244
+
217
245
/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
218
246
/// and if so, what meaning it has.
219
247
#[ derive( Debug ) ]
@@ -565,6 +593,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
565
593
lowered
566
594
}
567
595
596
+ fn create_stable_hashing_context ( & self ) -> LoweringHasher < ' _ > {
597
+ LoweringHasher {
598
+ source_map : CachingSourceMapView :: new ( self . sess . source_map ( ) ) ,
599
+ resolver : self . resolver ,
600
+ }
601
+ }
602
+
568
603
fn lower_node_id_generic (
569
604
& mut self ,
570
605
ast_node_id : NodeId ,
@@ -684,7 +719,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
684
719
span : Span ,
685
720
allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
686
721
) -> Span {
687
- span. mark_with_reason ( allow_internal_unstable, reason, self . sess . edition ( ) )
722
+ span. mark_with_reason (
723
+ allow_internal_unstable,
724
+ reason,
725
+ self . sess . edition ( ) ,
726
+ self . create_stable_hashing_context ( ) ,
727
+ )
688
728
}
689
729
690
730
fn with_anonymous_lifetime_mode < R > (
0 commit comments