@@ -24,20 +24,19 @@ use rustc_middle::ty::data_structures::IndexSet;
24
24
use rustc_middle:: ty:: { TyCtxt , TyCtxtFeed } ;
25
25
use rustc_proc_macro:: bridge:: client:: ProcMacro ;
26
26
use rustc_session:: config:: {
27
- self , CrateType , ExtendedTargetModifierInfo , ExternLocation , OptionsTargetModifiers ,
28
- TargetModifier ,
27
+ CrateType , ExtendedTargetModifierInfo , ExternLocation , OptionsTargetModifiers , TargetModifier ,
29
28
} ;
30
29
use rustc_session:: cstore:: { CrateDepKind , CrateSource , ExternCrate , ExternCrateSource } ;
31
30
use rustc_session:: lint:: { self , BuiltinLintDiag } ;
32
31
use rustc_session:: output:: validate_crate_name;
33
32
use rustc_session:: search_paths:: PathKind ;
34
33
use rustc_span:: edition:: Edition ;
35
34
use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , sym} ;
36
- use rustc_target:: spec:: { PanicStrategy , Target , TargetTuple } ;
35
+ use rustc_target:: spec:: { PanicStrategy , Target } ;
37
36
use tracing:: { debug, info, trace} ;
38
37
39
38
use crate :: errors;
40
- use crate :: locator:: { CrateError , CrateLocator , CratePaths } ;
39
+ use crate :: locator:: { CrateError , CrateLocator , CratePaths , CrateRejections } ;
41
40
use crate :: rmeta:: {
42
41
CrateDep , CrateMetadata , CrateNumMap , CrateRoot , MetadataBlob , TargetModifiers ,
43
42
} ;
@@ -684,61 +683,67 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
684
683
fn load_proc_macro < ' b > (
685
684
& self ,
686
685
locator : & mut CrateLocator < ' b > ,
686
+ crate_rejections : & mut CrateRejections ,
687
687
path_kind : PathKind ,
688
688
host_hash : Option < Svh > ,
689
689
) -> Result < Option < ( LoadResult , Option < Library > ) > , CrateError >
690
690
where
691
691
' a : ' b ,
692
692
{
693
- // Use a new crate locator so trying to load a proc macro doesn't affect the error
694
- // message we emit
695
- let mut proc_macro_locator = locator. clone ( ) ;
696
-
697
- // Try to load a proc macro
698
- proc_macro_locator. is_proc_macro = true ;
699
-
700
- // Load the proc macro crate for the target
701
- let ( locator, target_result) = if self . sess . opts . unstable_opts . dual_proc_macros {
702
- proc_macro_locator. reset ( ) ;
703
- let result = match self . load ( & mut proc_macro_locator) ? {
704
- Some ( LoadResult :: Previous ( cnum) ) => {
705
- return Ok ( Some ( ( LoadResult :: Previous ( cnum) , None ) ) ) ;
706
- }
707
- Some ( LoadResult :: Loaded ( library) ) => Some ( LoadResult :: Loaded ( library) ) ,
708
- None => return Ok ( None ) ,
709
- } ;
710
- locator. hash = host_hash;
711
- // Use the locator when looking for the host proc macro crate, as that is required
712
- // so we want it to affect the error message
713
- ( locator, result)
714
- } else {
715
- ( & mut proc_macro_locator, None )
716
- } ;
693
+ if self . sess . opts . unstable_opts . dual_proc_macros {
694
+ // Use a new crate locator and crate rejections so trying to load a proc macro doesn't
695
+ // affect the error message we emit
696
+ let mut proc_macro_locator = locator. clone ( ) ;
697
+
698
+ // Try to load a proc macro
699
+ proc_macro_locator. for_target_proc_macro ( self . sess , path_kind) ;
700
+
701
+ // Load the proc macro crate for the target
702
+ let target_result =
703
+ match self . load ( & mut proc_macro_locator, & mut CrateRejections :: default ( ) ) ? {
704
+ Some ( LoadResult :: Previous ( cnum) ) => {
705
+ return Ok ( Some ( ( LoadResult :: Previous ( cnum) , None ) ) ) ;
706
+ }
707
+ Some ( LoadResult :: Loaded ( library) ) => Some ( LoadResult :: Loaded ( library) ) ,
708
+ None => return Ok ( None ) ,
709
+ } ;
717
710
718
- // Load the proc macro crate for the host
711
+ // Use the existing crate_rejections as we want the error message to be affected by
712
+ // loading the host proc macro.
713
+ * crate_rejections = CrateRejections :: default ( ) ;
719
714
720
- locator. reset ( ) ;
721
- locator. is_proc_macro = true ;
722
- locator. target = & self . sess . host ;
723
- locator. tuple = TargetTuple :: from_tuple ( config:: host_tuple ( ) ) ;
724
- locator. filesearch = self . sess . host_filesearch ( ) ;
725
- locator. path_kind = path_kind;
715
+ // Load the proc macro crate for the host
716
+ locator. for_proc_macro ( self . sess , path_kind) ;
726
717
727
- let Some ( host_result) = self . load ( locator) ? else {
728
- return Ok ( None ) ;
729
- } ;
718
+ locator. hash = host_hash;
719
+
720
+ let Some ( host_result) = self . load ( locator, crate_rejections) ? else {
721
+ return Ok ( None ) ;
722
+ } ;
730
723
731
- Ok ( Some ( if self . sess . opts . unstable_opts . dual_proc_macros {
732
724
let host_result = match host_result {
733
725
LoadResult :: Previous ( ..) => {
734
726
panic ! ( "host and target proc macros must be loaded in lock-step" )
735
727
}
736
728
LoadResult :: Loaded ( library) => library,
737
729
} ;
738
- ( target_result. unwrap ( ) , Some ( host_result) )
730
+ Ok ( Some ( ( target_result. unwrap ( ) , Some ( host_result) ) ) )
739
731
} else {
740
- ( host_result, None )
741
- } ) )
732
+ // Use a new crate locator and crate rejections so trying to load a proc macro doesn't
733
+ // affect the error message we emit
734
+ let mut proc_macro_locator = locator. clone ( ) ;
735
+
736
+ // Load the proc macro crate for the host
737
+ proc_macro_locator. for_proc_macro ( self . sess , path_kind) ;
738
+
739
+ let Some ( host_result) =
740
+ self . load ( & mut proc_macro_locator, & mut CrateRejections :: default ( ) ) ?
741
+ else {
742
+ return Ok ( None ) ;
743
+ } ;
744
+
745
+ Ok ( Some ( ( host_result, None ) ) )
746
+ }
742
747
}
743
748
744
749
fn resolve_crate (
@@ -799,15 +804,21 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
799
804
extra_filename,
800
805
path_kind,
801
806
) ;
807
+ let mut crate_rejections = CrateRejections :: default ( ) ;
802
808
803
- match self . load ( & mut locator) ? {
809
+ match self . load ( & mut locator, & mut crate_rejections ) ? {
804
810
Some ( res) => ( res, None ) ,
805
811
None => {
806
812
info ! ( "falling back to loading proc_macro" ) ;
807
813
dep_kind = CrateDepKind :: MacrosOnly ;
808
- match self . load_proc_macro ( & mut locator, path_kind, host_hash) ? {
814
+ match self . load_proc_macro (
815
+ & mut locator,
816
+ & mut crate_rejections,
817
+ path_kind,
818
+ host_hash,
819
+ ) ? {
809
820
Some ( res) => res,
810
- None => return Err ( locator. into_error ( dep_root. cloned ( ) ) ) ,
821
+ None => return Err ( locator. into_error ( crate_rejections , dep_root. cloned ( ) ) ) ,
811
822
}
812
823
}
813
824
}
@@ -837,8 +848,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
837
848
}
838
849
}
839
850
840
- fn load ( & self , locator : & mut CrateLocator < ' _ > ) -> Result < Option < LoadResult > , CrateError > {
841
- let Some ( library) = locator. maybe_load_library_crate ( ) ? else {
851
+ fn load (
852
+ & self ,
853
+ locator : & CrateLocator < ' _ > ,
854
+ crate_rejections : & mut CrateRejections ,
855
+ ) -> Result < Option < LoadResult > , CrateError > {
856
+ let Some ( library) = locator. maybe_load_library_crate ( crate_rejections) ? else {
842
857
return Ok ( None ) ;
843
858
} ;
844
859
0 commit comments