@@ -22,8 +22,10 @@ use rustc_middle::bug;
22
22
use rustc_middle:: ty:: data_structures:: IndexSet ;
23
23
use rustc_middle:: ty:: { TyCtxt , TyCtxtFeed } ;
24
24
use rustc_proc_macro:: bridge:: client:: ProcMacro ;
25
+ use rustc_session:: Session ;
25
26
use rustc_session:: config:: {
26
- CrateType , ExtendedTargetModifierInfo , ExternLocation , OptionsTargetModifiers , TargetModifier ,
27
+ CrateType , ExtendedTargetModifierInfo , ExternLocation , Externs , OptionsTargetModifiers ,
28
+ TargetModifier ,
27
29
} ;
28
30
use rustc_session:: cstore:: { CrateDepKind , CrateSource , ExternCrate , ExternCrateSource } ;
29
31
use rustc_session:: lint:: { self , BuiltinLintDiag } ;
@@ -480,7 +482,7 @@ impl CStore {
480
482
481
483
fn existing_match (
482
484
& self ,
483
- tcx : TyCtxt < ' _ > ,
485
+ externs : & Externs ,
484
486
name : Symbol ,
485
487
hash : Option < Svh > ,
486
488
kind : PathKind ,
@@ -510,7 +512,7 @@ impl CStore {
510
512
// `source` stores paths which are normalized which may be different
511
513
// from the strings on the command line.
512
514
let source = self . get_crate_data ( cnum) . cdata . source ( ) ;
513
- if let Some ( entry) = tcx . sess . opts . externs . get ( name. as_str ( ) ) {
515
+ if let Some ( entry) = externs. get ( name. as_str ( ) ) {
514
516
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
515
517
if let Some ( mut files) = entry. files ( ) {
516
518
if files. any ( |l| {
@@ -561,9 +563,9 @@ impl CStore {
561
563
/// Sometimes the directly dependent crate is not specified by `--extern`, in this case,
562
564
/// `private-dep` is none during loading. This is equivalent to the scenario where the
563
565
/// command parameter is set to `public-dependency`
564
- fn is_private_dep < ' tcx > (
566
+ fn is_private_dep (
565
567
& self ,
566
- tcx : TyCtxt < ' tcx > ,
568
+ externs : & Externs ,
567
569
name : Symbol ,
568
570
private_dep : Option < bool > ,
569
571
origin : CrateOrigin < ' _ > ,
@@ -572,7 +574,7 @@ impl CStore {
572
574
return true ;
573
575
}
574
576
575
- let extern_private = tcx . sess . opts . externs . get ( name. as_str ( ) ) . map ( |e| e. is_private_dep ) ;
577
+ let extern_private = externs. get ( name. as_str ( ) ) . map ( |e| e. is_private_dep ) ;
576
578
match ( extern_private, private_dep) {
577
579
// Explicit non-private via `--extern`, explicit non-private from metadata, or
578
580
// unspecified with default to public.
@@ -598,7 +600,7 @@ impl CStore {
598
600
let Library { source, metadata } = lib;
599
601
let crate_root = metadata. get_root ( ) ;
600
602
let host_hash = host_lib. as_ref ( ) . map ( |lib| lib. metadata . get_root ( ) . hash ( ) ) ;
601
- let private_dep = self . is_private_dep ( tcx, name, private_dep, origin) ;
603
+ let private_dep = self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep, origin) ;
602
604
603
605
// Claim this crate number and cache it
604
606
let feed = self . intern_stable_crate_id ( tcx, & crate_root) ?;
@@ -641,7 +643,7 @@ impl CStore {
641
643
None => ( & source, & crate_root) ,
642
644
} ;
643
645
let dlsym_dylib = dlsym_source. dylib . as_ref ( ) . expect ( "no dylib for a proc-macro crate" ) ;
644
- Some ( self . dlsym_proc_macros ( tcx, & dlsym_dylib. 0 , dlsym_root. stable_crate_id ( ) ) ?)
646
+ Some ( self . dlsym_proc_macros ( tcx. sess , & dlsym_dylib. 0 , dlsym_root. stable_crate_id ( ) ) ?)
645
647
} else {
646
648
None
647
649
} ;
@@ -665,24 +667,24 @@ impl CStore {
665
667
Ok ( cnum)
666
668
}
667
669
668
- fn load_proc_macro < ' b , ' tcx > (
670
+ fn load_proc_macro < ' a , ' b > (
669
671
& self ,
670
- tcx : TyCtxt < ' tcx > ,
672
+ sess : & ' a Session ,
671
673
locator : & mut CrateLocator < ' b > ,
672
674
crate_rejections : & mut CrateRejections ,
673
675
path_kind : PathKind ,
674
676
host_hash : Option < Svh > ,
675
677
) -> Result < Option < ( LoadResult , Option < Library > ) > , CrateError >
676
678
where
677
- ' tcx : ' b ,
679
+ ' a : ' b ,
678
680
{
679
- if tcx . sess . opts . unstable_opts . dual_proc_macros {
681
+ if sess. opts . unstable_opts . dual_proc_macros {
680
682
// Use a new crate locator and crate rejections so trying to load a proc macro doesn't
681
683
// affect the error message we emit
682
684
let mut proc_macro_locator = locator. clone ( ) ;
683
685
684
686
// Try to load a proc macro
685
- proc_macro_locator. for_target_proc_macro ( tcx . sess , path_kind) ;
687
+ proc_macro_locator. for_target_proc_macro ( sess, path_kind) ;
686
688
687
689
// Load the proc macro crate for the target
688
690
let target_result =
@@ -699,7 +701,7 @@ impl CStore {
699
701
* crate_rejections = CrateRejections :: default ( ) ;
700
702
701
703
// Load the proc macro crate for the host
702
- locator. for_proc_macro ( tcx . sess , path_kind) ;
704
+ locator. for_proc_macro ( sess, path_kind) ;
703
705
704
706
locator. hash = host_hash;
705
707
@@ -720,7 +722,7 @@ impl CStore {
720
722
let mut proc_macro_locator = locator. clone ( ) ;
721
723
722
724
// Load the proc macro crate for the host
723
- proc_macro_locator. for_proc_macro ( tcx . sess , path_kind) ;
725
+ proc_macro_locator. for_proc_macro ( sess, path_kind) ;
724
726
725
727
let Some ( host_result) =
726
728
self . load ( & mut proc_macro_locator, & mut CrateRejections :: default ( ) ) ?
@@ -782,7 +784,9 @@ impl CStore {
782
784
let path_kind = if dep. is_some ( ) { PathKind :: Dependency } else { PathKind :: Crate } ;
783
785
let private_dep = origin. private_dep ( ) ;
784
786
785
- let result = if let Some ( cnum) = self . existing_match ( tcx, name, hash, path_kind) {
787
+ let result = if let Some ( cnum) =
788
+ self . existing_match ( & tcx. sess . opts . externs , name, hash, path_kind)
789
+ {
786
790
( LoadResult :: Previous ( cnum) , None )
787
791
} else {
788
792
info ! ( "falling back to a load" ) ;
@@ -805,7 +809,7 @@ impl CStore {
805
809
info ! ( "falling back to loading proc_macro" ) ;
806
810
dep_kind = CrateDepKind :: MacrosOnly ;
807
811
match self . load_proc_macro (
808
- tcx,
812
+ tcx. sess ,
809
813
& mut locator,
810
814
& mut crate_rejections,
811
815
path_kind,
@@ -825,7 +829,8 @@ impl CStore {
825
829
// not specified by `--extern` on command line parameters, it may be
826
830
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
827
831
// `public-dependency` here.
828
- let private_dep = self . is_private_dep ( tcx, name, private_dep, origin) ;
832
+ let private_dep =
833
+ self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep, origin) ;
829
834
let data = self . get_crate_data_mut ( cnum) ;
830
835
if data. is_proc_macro_crate ( ) {
831
836
dep_kind = CrateDepKind :: MacrosOnly ;
@@ -924,13 +929,13 @@ impl CStore {
924
929
Ok ( crate_num_map)
925
930
}
926
931
927
- fn dlsym_proc_macros < ' tcx > (
932
+ fn dlsym_proc_macros (
928
933
& self ,
929
- tcx : TyCtxt < ' tcx > ,
934
+ sess : & Session ,
930
935
path : & Path ,
931
936
stable_crate_id : StableCrateId ,
932
937
) -> Result < & ' static [ ProcMacro ] , CrateError > {
933
- let sym_name = tcx . sess . generate_proc_macro_decls_symbol ( stable_crate_id) ;
938
+ let sym_name = sess. generate_proc_macro_decls_symbol ( stable_crate_id) ;
934
939
debug ! ( "trying to dlsym proc_macros {} for symbol `{}`" , path. display( ) , sym_name) ;
935
940
936
941
unsafe {
0 commit comments