@@ -21,7 +21,7 @@ use rustc_middle::ty::{self, TyCtxt};
21
21
use rustc_middle:: util:: Providers ;
22
22
use rustc_session:: cstore:: { CrateStore , ExternCrate } ;
23
23
use rustc_session:: { Session , StableCrateId } ;
24
- use rustc_span:: hygiene:: { ExpnHash , ExpnId } ;
24
+ use rustc_span:: hygiene:: ExpnId ;
25
25
use rustc_span:: symbol:: { kw, Symbol } ;
26
26
use rustc_span:: Span ;
27
27
@@ -378,6 +378,7 @@ provide! { tcx, def_id, other, cdata,
378
378
}
379
379
380
380
pub ( in crate :: rmeta) fn provide ( providers : & mut Providers ) {
381
+ provide_cstore_hooks ( providers) ;
381
382
// FIXME(#44234) - almost all of these queries have no sub-queries and
382
383
// therefore no actual inputs, they're just reading tables calculated in
383
384
// resolve! Does this work? Unsure! That's what the issue is about
@@ -649,26 +650,27 @@ impl CrateStore for CStore {
649
650
fn def_path_hash ( & self , def : DefId ) -> DefPathHash {
650
651
self . get_crate_data ( def. krate ) . def_path_hash ( def. index )
651
652
}
653
+ }
652
654
653
- fn def_path_hash_to_def_id ( & self , cnum : CrateNum , hash : DefPathHash ) -> DefId {
654
- let def_index = self . get_crate_data ( cnum) . def_path_hash_to_def_index ( hash) ;
655
+ fn provide_cstore_hooks ( providers : & mut Providers ) {
656
+ providers. hooks . def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
657
+ // If this is a DefPathHash from an upstream crate, let the CrateStore map
658
+ // it to a DefId.
659
+ let cstore = CStore :: from_tcx ( tcx. tcx ) ;
660
+ let cnum = cstore. stable_crate_id_to_crate_num ( stable_crate_id) ;
661
+ let def_index = cstore. get_crate_data ( cnum) . def_path_hash_to_def_index ( hash) ;
655
662
DefId { krate : cnum, index : def_index }
656
- }
657
-
658
- fn expn_hash_to_expn_id (
659
- & self ,
660
- sess : & Session ,
661
- cnum : CrateNum ,
662
- index_guess : u32 ,
663
- hash : ExpnHash ,
664
- ) -> ExpnId {
665
- self . get_crate_data ( cnum) . expn_hash_to_expn_id ( sess, index_guess, hash)
666
- }
663
+ } ;
667
664
668
- fn import_source_files ( & self , sess : & Session , cnum : CrateNum ) {
669
- let cdata = self . get_crate_data ( cnum) ;
665
+ providers. hooks . expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
666
+ let cstore = CStore :: from_tcx ( tcx. tcx ) ;
667
+ cstore. get_crate_data ( cnum) . expn_hash_to_expn_id ( tcx. sess , index_guess, hash)
668
+ } ;
669
+ providers. hooks . import_source_files = |tcx, cnum| {
670
+ let cstore = CStore :: from_tcx ( tcx. tcx ) ;
671
+ let cdata = cstore. get_crate_data ( cnum) ;
670
672
for file_index in 0 ..cdata. root . source_map . size ( ) {
671
- cdata. imported_source_file ( file_index as u32 , sess) ;
673
+ cdata. imported_source_file ( file_index as u32 , tcx . sess ) ;
672
674
}
673
- }
675
+ } ;
674
676
}
0 commit comments