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