@@ -24,20 +24,19 @@ use rustc_middle::ty::data_structures::IndexSet;
2424use  rustc_middle:: ty:: { TyCtxt ,  TyCtxtFeed } ; 
2525use  rustc_proc_macro:: bridge:: client:: ProcMacro ; 
2626use  rustc_session:: config:: { 
27-     self ,  CrateType ,  ExtendedTargetModifierInfo ,  ExternLocation ,  OptionsTargetModifiers , 
28-     TargetModifier , 
27+     CrateType ,  ExtendedTargetModifierInfo ,  ExternLocation ,  OptionsTargetModifiers ,  TargetModifier , 
2928} ; 
3029use  rustc_session:: cstore:: { CrateDepKind ,  CrateSource ,  ExternCrate ,  ExternCrateSource } ; 
3130use  rustc_session:: lint:: { self ,  BuiltinLintDiag } ; 
3231use  rustc_session:: output:: validate_crate_name; 
3332use  rustc_session:: search_paths:: PathKind ; 
3433use  rustc_span:: edition:: Edition ; 
3534use  rustc_span:: { DUMMY_SP ,  Ident ,  Span ,  Symbol ,  sym} ; 
36- use  rustc_target:: spec:: { PanicStrategy ,  Target ,   TargetTuple } ; 
35+ use  rustc_target:: spec:: { PanicStrategy ,  Target } ; 
3736use  tracing:: { debug,  info,  trace} ; 
3837
3938use  crate :: errors; 
40- use  crate :: locator:: { CrateError ,  CrateLocator ,  CratePaths } ; 
39+ use  crate :: locator:: { CrateError ,  CrateLocator ,  CratePaths ,   CrateRejections } ; 
4140use  crate :: rmeta:: { 
4241    CrateDep ,  CrateMetadata ,  CrateNumMap ,  CrateRoot ,  MetadataBlob ,  TargetModifiers , 
4342} ; 
@@ -684,61 +683,67 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
684683    fn  load_proc_macro < ' b > ( 
685684        & self , 
686685        locator :  & mut  CrateLocator < ' b > , 
686+         crate_rejections :  & mut  CrateRejections , 
687687        path_kind :  PathKind , 
688688        host_hash :  Option < Svh > , 
689689    )  -> Result < Option < ( LoadResult ,  Option < Library > ) > ,  CrateError > 
690690    where 
691691        ' a :  ' b , 
692692    { 
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+                 } ; 
717710
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 ( ) ; 
719714
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) ; 
726717
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+             } ; 
730723
731-         Ok ( Some ( if  self . sess . opts . unstable_opts . dual_proc_macros  { 
732724            let  host_result = match  host_result { 
733725                LoadResult :: Previous ( ..)  => { 
734726                    panic ! ( "host and target proc macros must be loaded in lock-step" ) 
735727                } 
736728                LoadResult :: Loaded ( library)  => library, 
737729            } ; 
738-             ( target_result. unwrap ( ) ,  Some ( host_result) ) 
730+             Ok ( Some ( ( target_result. unwrap ( ) ,  Some ( host_result) ) ) ) 
739731        }  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+         } 
742747    } 
743748
744749    fn  resolve_crate ( 
@@ -799,15 +804,21 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
799804                extra_filename, 
800805                path_kind, 
801806            ) ; 
807+             let  mut  crate_rejections = CrateRejections :: default ( ) ; 
802808
803-             match  self . load ( & mut  locator) ? { 
809+             match  self . load ( & mut  locator,   & mut  crate_rejections ) ? { 
804810                Some ( res)  => ( res,  None ) , 
805811                None  => { 
806812                    info ! ( "falling back to loading proc_macro" ) ; 
807813                    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+                     ) ? { 
809820                        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 ( ) ) ) , 
811822                    } 
812823                } 
813824            } 
@@ -837,8 +848,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
837848        } 
838849    } 
839850
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  { 
842857            return  Ok ( None ) ; 
843858        } ; 
844859
0 commit comments