@@ -388,6 +388,15 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
388
388
None
389
389
}
390
390
391
+ // The `dependency` type is determined by the command line arguments(`--extern`) and
392
+ // `private_dep`. However, sometimes the directly dependent crate is not specified by
393
+ // `--extern`, in this case, `private-dep` is none during loading. This is equivalent to the
394
+ // scenario where the command parameter is set to `public-dependency`
395
+ fn is_private_dep ( & self , name : & str , private_dep : Option < bool > ) -> bool {
396
+ self . sess . opts . externs . get ( name) . map_or ( private_dep. unwrap_or ( false ) , |e| e. is_private_dep )
397
+ && private_dep. unwrap_or ( true )
398
+ }
399
+
391
400
fn register_crate (
392
401
& mut self ,
393
402
host_lib : Option < Library > ,
@@ -402,14 +411,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
402
411
let Library { source, metadata } = lib;
403
412
let crate_root = metadata. get_root ( ) ;
404
413
let host_hash = host_lib. as_ref ( ) . map ( |lib| lib. metadata . get_root ( ) . hash ( ) ) ;
405
-
406
- let private_dep = self
407
- . sess
408
- . opts
409
- . externs
410
- . get ( name. as_str ( ) )
411
- . map_or ( private_dep. unwrap_or ( false ) , |e| e. is_private_dep )
412
- && private_dep. unwrap_or ( true ) ;
414
+ let private_dep = self . is_private_dep ( name. as_str ( ) , private_dep) ;
413
415
414
416
// Claim this crate number and cache it
415
417
let cnum = self . cstore . intern_stable_crate_id ( & crate_root) ?;
@@ -599,14 +601,17 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
599
601
600
602
match result {
601
603
( LoadResult :: Previous ( cnum) , None ) => {
604
+ // When `private_dep` is none, it indicates the directly dependent crate. If it is
605
+ // not specified by `--extern` on command line parameters, it may be
606
+ // `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
607
+ // `public-dependency` here.
608
+ let private_dep = self . is_private_dep ( name. as_str ( ) , private_dep) ;
602
609
let data = self . cstore . get_crate_data_mut ( cnum) ;
603
610
if data. is_proc_macro_crate ( ) {
604
611
dep_kind = CrateDepKind :: MacrosOnly ;
605
612
}
606
613
data. set_dep_kind ( cmp:: max ( data. dep_kind ( ) , dep_kind) ) ;
607
- if let Some ( private_dep) = private_dep {
608
- data. update_and_private_dep ( private_dep) ;
609
- }
614
+ data. update_and_private_dep ( private_dep) ;
610
615
Ok ( cnum)
611
616
}
612
617
( LoadResult :: Loaded ( library) , host_library) => {
0 commit comments