@@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc;
4848use rustc_errors:: { struct_span_err, Applicability } ;
4949use rustc_hir as hir;
5050use 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 } ;
5252use rustc_hir:: definitions:: { DefKey , DefPathData , Definitions } ;
5353use rustc_hir:: intravisit;
5454use rustc_hir:: { ConstArg , GenericArg , ParamName } ;
@@ -59,7 +59,7 @@ use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
5959use rustc_session:: Session ;
6060use rustc_span:: edition:: Edition ;
6161use rustc_span:: hygiene:: ExpnId ;
62- use rustc_span:: source_map:: { respan, DesugaringKind } ;
62+ use rustc_span:: source_map:: { respan, CachingSourceMapView , DesugaringKind } ;
6363use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
6464use rustc_span:: { Span , DUMMY_SP } ;
6565use rustc_target:: spec:: abi:: Abi ;
@@ -204,6 +204,8 @@ pub trait ResolverAstLowering {
204204
205205 fn local_def_id ( & self , node : NodeId ) -> LocalDefId ;
206206
207+ fn def_path_hash ( & self , def_id : DefId ) -> DefPathHash ;
208+
207209 fn create_def (
208210 & mut self ,
209211 parent : LocalDefId ,
@@ -214,6 +216,32 @@ pub trait ResolverAstLowering {
214216 ) -> LocalDefId ;
215217}
216218
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+
217245/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
218246/// and if so, what meaning it has.
219247#[ derive( Debug ) ]
@@ -565,6 +593,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
565593 lowered
566594 }
567595
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+
568603 fn lower_node_id_generic (
569604 & mut self ,
570605 ast_node_id : NodeId ,
@@ -684,7 +719,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
684719 span : Span ,
685720 allow_internal_unstable : Option < Lrc < [ Symbol ] > > ,
686721 ) -> 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+ )
688728 }
689729
690730 fn with_anonymous_lifetime_mode < R > (
0 commit comments