@@ -156,8 +156,8 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
156156enum CrateOrigin < ' a > {
157157 /// This crate was a dependency of another crate.
158158 IndirectDependency {
159- /// Where this dependency was included from.
160- dep_root : & ' a CratePaths ,
159+ /// Where this dependency was included from. Should only be used in error messages.
160+ dep_root_for_errors : & ' a CratePaths ,
161161 /// True if the parent is private, meaning the dependent should also be private.
162162 parent_private : bool ,
163163 /// Dependency info about this crate.
@@ -171,9 +171,11 @@ enum CrateOrigin<'a> {
171171
172172impl < ' a > CrateOrigin < ' a > {
173173 /// Return the dependency root, if any.
174- fn dep_root ( & self ) -> Option < & ' a CratePaths > {
174+ fn dep_root_for_errors ( & self ) -> Option < & ' a CratePaths > {
175175 match self {
176- CrateOrigin :: IndirectDependency { dep_root, .. } => Some ( dep_root) ,
176+ CrateOrigin :: IndirectDependency { dep_root_for_errors, .. } => {
177+ Some ( dep_root_for_errors)
178+ }
177179 _ => None ,
178180 }
179181 }
@@ -193,6 +195,7 @@ impl<'a> CrateOrigin<'a> {
193195 CrateOrigin :: IndirectDependency { parent_private, dep, .. } => {
194196 Some ( dep. is_private || * parent_private)
195197 }
198+ CrateOrigin :: Injected => Some ( true ) ,
196199 _ => None ,
197200 }
198201 }
@@ -544,17 +547,7 @@ impl CStore {
544547 /// Sometimes the directly dependent crate is not specified by `--extern`, in this case,
545548 /// `private-dep` is none during loading. This is equivalent to the scenario where the
546549 /// command parameter is set to `public-dependency`
547- fn is_private_dep (
548- & self ,
549- externs : & Externs ,
550- name : Symbol ,
551- private_dep : Option < bool > ,
552- origin : CrateOrigin < ' _ > ,
553- ) -> bool {
554- if matches ! ( origin, CrateOrigin :: Injected ) {
555- return true ;
556- }
557-
550+ fn is_private_dep ( & self , externs : & Externs , name : Symbol , private_dep : Option < bool > ) -> bool {
558551 let extern_private = externs. get ( name. as_str ( ) ) . map ( |e| e. is_private_dep ) ;
559552 match ( extern_private, private_dep) {
560553 // Explicit non-private via `--extern`, explicit non-private from metadata, or
@@ -581,7 +574,7 @@ impl CStore {
581574 let Library { source, metadata } = lib;
582575 let crate_root = metadata. get_root ( ) ;
583576 let host_hash = host_lib. as_ref ( ) . map ( |lib| lib. metadata . get_root ( ) . hash ( ) ) ;
584- let private_dep = self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep, origin ) ;
577+ let private_dep = self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep) ;
585578
586579 // Claim this crate number and cache it
587580 let feed = self . intern_stable_crate_id ( tcx, & crate_root) ?;
@@ -597,16 +590,16 @@ impl CStore {
597590 // Maintain a reference to the top most crate.
598591 // Stash paths for top-most crate locally if necessary.
599592 let crate_paths;
600- let dep_root = if let Some ( dep_root ) = origin. dep_root ( ) {
601- dep_root
593+ let dep_root_for_errors = if let Some ( dep_root_for_errors ) = origin. dep_root_for_errors ( ) {
594+ dep_root_for_errors
602595 } else {
603596 crate_paths = CratePaths :: new ( crate_root. name ( ) , source. clone ( ) ) ;
604597 & crate_paths
605598 } ;
606599
607600 let cnum_map = self . resolve_crate_deps (
608601 tcx,
609- dep_root ,
602+ dep_root_for_errors ,
610603 & crate_root,
611604 & metadata,
612605 cnum,
@@ -726,7 +719,7 @@ impl CStore {
726719 self . used_extern_options . insert ( name) ;
727720 match self . maybe_resolve_crate ( tcx, name, dep_kind, origin) {
728721 Ok ( cnum) => {
729- self . set_used_recursively ( tcx , cnum) ;
722+ self . set_used_recursively ( cnum) ;
730723 Some ( cnum)
731724 }
732725 Err ( err) => {
@@ -735,7 +728,7 @@ impl CStore {
735728 . maybe_resolve_crate (
736729 tcx,
737730 sym:: core,
738- CrateDepKind :: Explicit ,
731+ CrateDepKind :: Unconditional ,
739732 CrateOrigin :: Extern ,
740733 )
741734 . is_err ( ) ;
@@ -757,7 +750,7 @@ impl CStore {
757750 return Err ( CrateError :: NonAsciiName ( name) ) ;
758751 }
759752
760- let dep_root = origin. dep_root ( ) ;
753+ let dep_root_for_errors = origin. dep_root_for_errors ( ) ;
761754 let dep = origin. dep ( ) ;
762755 let hash = dep. map ( |d| d. hash ) ;
763756 let host_hash = dep. map ( |d| d. host_hash ) . flatten ( ) ;
@@ -795,7 +788,11 @@ impl CStore {
795788 host_hash,
796789 ) ? {
797790 Some ( res) => res,
798- None => return Err ( locator. into_error ( crate_rejections, dep_root. cloned ( ) ) ) ,
791+ None => {
792+ return Err (
793+ locator. into_error ( crate_rejections, dep_root_for_errors. cloned ( ) )
794+ ) ;
795+ }
799796 }
800797 }
801798 }
@@ -808,8 +805,7 @@ impl CStore {
808805 // not specified by `--extern` on command line parameters, it may be
809806 // `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
810807 // `public-dependency` here.
811- let private_dep =
812- self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep, origin) ;
808+ let private_dep = self . is_private_dep ( & tcx. sess . opts . externs , name, private_dep) ;
813809 let data = self . get_crate_data_mut ( cnum) ;
814810 if data. is_proc_macro_crate ( ) {
815811 dep_kind = CrateDepKind :: MacrosOnly ;
@@ -856,7 +852,7 @@ impl CStore {
856852 fn resolve_crate_deps (
857853 & mut self ,
858854 tcx : TyCtxt < ' _ > ,
859- dep_root : & CratePaths ,
855+ dep_root_for_errors : & CratePaths ,
860856 crate_root : & CrateRoot ,
861857 metadata : & MetadataBlob ,
862858 krate : CrateNum ,
@@ -866,7 +862,7 @@ impl CStore {
866862 debug ! (
867863 "resolving deps of external crate `{}` with dep root `{}`" ,
868864 crate_root. name( ) ,
869- dep_root . name
865+ dep_root_for_errors . name
870866 ) ;
871867 if crate_root. is_proc_macro_crate ( ) {
872868 return Ok ( CrateNumMap :: new ( ) ) ;
@@ -896,7 +892,7 @@ impl CStore {
896892 dep. name ,
897893 dep_kind,
898894 CrateOrigin :: IndirectDependency {
899- dep_root ,
895+ dep_root_for_errors ,
900896 parent_private : parent_is_private,
901897 dep : & dep,
902898 } ,
@@ -979,9 +975,15 @@ impl CStore {
979975 } ;
980976 info ! ( "panic runtime not found -- loading {}" , name) ;
981977
982- let Some ( cnum) =
983- self . resolve_crate ( tcx, name, DUMMY_SP , CrateDepKind :: Implicit , CrateOrigin :: Injected )
984- else {
978+ // This has to be conditional as both panic_unwind and panic_abort may be present in the
979+ // crate graph at the same time. One of them will later be activated in dependency_formats.
980+ let Some ( cnum) = self . resolve_crate (
981+ tcx,
982+ name,
983+ DUMMY_SP ,
984+ CrateDepKind :: Conditional ,
985+ CrateOrigin :: Injected ,
986+ ) else {
985987 return ;
986988 } ;
987989 let data = self . get_crate_data ( cnum) ;
@@ -1009,9 +1011,13 @@ impl CStore {
10091011 info ! ( "loading profiler" ) ;
10101012
10111013 let name = Symbol :: intern ( & tcx. sess . opts . unstable_opts . profiler_runtime ) ;
1012- let Some ( cnum) =
1013- self . resolve_crate ( tcx, name, DUMMY_SP , CrateDepKind :: Implicit , CrateOrigin :: Injected )
1014- else {
1014+ let Some ( cnum) = self . resolve_crate (
1015+ tcx,
1016+ name,
1017+ DUMMY_SP ,
1018+ CrateDepKind :: Unconditional ,
1019+ CrateOrigin :: Injected ,
1020+ ) else {
10151021 return ;
10161022 } ;
10171023 let data = self . get_crate_data ( cnum) ;
@@ -1131,7 +1137,7 @@ impl CStore {
11311137 tcx,
11321138 name_interned,
11331139 DUMMY_SP ,
1134- CrateDepKind :: Explicit ,
1140+ CrateDepKind :: Unconditional ,
11351141 CrateOrigin :: Extern ,
11361142 ) ;
11371143 }
@@ -1163,7 +1169,7 @@ impl CStore {
11631169 tcx,
11641170 sym:: compiler_builtins,
11651171 krate. spans . inner_span . shrink_to_lo ( ) ,
1166- CrateDepKind :: Explicit ,
1172+ CrateDepKind :: Unconditional ,
11671173 CrateOrigin :: Injected ,
11681174 ) else {
11691175 info ! ( "`compiler_builtins` not resolved" ) ;
@@ -1280,7 +1286,7 @@ impl CStore {
12801286 let dep_kind = if attr:: contains_name ( & item. attrs , sym:: no_link) {
12811287 CrateDepKind :: MacrosOnly
12821288 } else {
1283- CrateDepKind :: Explicit
1289+ CrateDepKind :: Unconditional
12841290 } ;
12851291
12861292 let cnum =
@@ -1310,7 +1316,7 @@ impl CStore {
13101316 span : Span ,
13111317 ) -> Option < CrateNum > {
13121318 let cnum =
1313- self . resolve_crate ( tcx, name, span, CrateDepKind :: Explicit , CrateOrigin :: Extern ) ?;
1319+ self . resolve_crate ( tcx, name, span, CrateDepKind :: Unconditional , CrateOrigin :: Extern ) ?;
13141320
13151321 self . update_extern_crate (
13161322 cnum,
@@ -1328,7 +1334,7 @@ impl CStore {
13281334 }
13291335
13301336 pub fn maybe_process_path_extern ( & mut self , tcx : TyCtxt < ' _ > , name : Symbol ) -> Option < CrateNum > {
1331- self . maybe_resolve_crate ( tcx, name, CrateDepKind :: Explicit , CrateOrigin :: Extern ) . ok ( )
1337+ self . maybe_resolve_crate ( tcx, name, CrateDepKind :: Unconditional , CrateOrigin :: Extern ) . ok ( )
13321338 }
13331339}
13341340
0 commit comments