@@ -168,7 +168,10 @@ impl<'a> std::fmt::Debug for CrateDump<'a> {
168
168
enum CrateOrigin < ' a > {
169
169
/// This crate was a dependency of another crate.
170
170
IndirectDependency {
171
+ /// Where this dependency was included from.
171
172
dep_root : & ' a CratePaths ,
173
+ /// True if the parent is private, meaning the dependent should also be private.
174
+ parent_private : bool ,
172
175
/// Dependency info about this crate.
173
176
dep : & ' a CrateDep ,
174
177
} ,
@@ -194,6 +197,17 @@ impl<'a> CrateOrigin<'a> {
194
197
_ => None ,
195
198
}
196
199
}
200
+
201
+ /// `Some(true)` if the dependency is private or its parent is private, `Some(false)` if the
202
+ /// dependency is not private, `None` if it could not be determined.
203
+ fn private_dep ( & self ) -> Option < bool > {
204
+ match self {
205
+ CrateOrigin :: IndirectDependency { parent_private, dep, .. } => {
206
+ Some ( dep. is_private || * parent_private)
207
+ }
208
+ _ => None ,
209
+ }
210
+ }
197
211
}
198
212
199
213
impl CStore {
@@ -585,7 +599,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
585
599
& crate_paths
586
600
} ;
587
601
588
- let cnum_map = self . resolve_crate_deps ( dep_root, & crate_root, & metadata, cnum, dep_kind) ?;
602
+ let cnum_map =
603
+ self . resolve_crate_deps ( dep_root, & crate_root, & metadata, cnum, dep_kind, private_dep) ?;
589
604
590
605
let raw_proc_macros = if crate_root. is_proc_macro_crate ( ) {
591
606
let temp_root;
@@ -722,7 +737,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
722
737
let host_hash = dep. map ( |d| d. host_hash ) . flatten ( ) ;
723
738
let extra_filename = dep. map ( |d| & d. extra_filename [ ..] ) ;
724
739
let path_kind = if dep. is_some ( ) { PathKind :: Dependency } else { PathKind :: Crate } ;
725
- let private_dep = dep . map ( |d| d . is_private ) ;
740
+ let private_dep = origin . private_dep ( ) ;
726
741
727
742
let result = if let Some ( cnum) = self . existing_match ( name, hash, path_kind) {
728
743
( LoadResult :: Previous ( cnum) , None )
@@ -819,6 +834,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
819
834
metadata : & MetadataBlob ,
820
835
krate : CrateNum ,
821
836
dep_kind : CrateDepKind ,
837
+ parent_is_private : bool ,
822
838
) -> Result < CrateNumMap , CrateError > {
823
839
debug ! (
824
840
"resolving deps of external crate `{}` with dep root `{}`" ,
@@ -837,11 +853,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
837
853
crate_num_map. push ( krate) ;
838
854
for dep in deps {
839
855
info ! (
840
- "resolving dep `{}`->`{}` hash: `{}` extra filename: `{}`" ,
856
+ "resolving dep `{}`->`{}` hash: `{}` extra filename: `{}` private {} " ,
841
857
crate_root. name( ) ,
842
858
dep. name,
843
859
dep. hash,
844
- dep. extra_filename
860
+ dep. extra_filename,
861
+ dep. is_private,
845
862
) ;
846
863
let dep_kind = match dep_kind {
847
864
CrateDepKind :: MacrosOnly => CrateDepKind :: MacrosOnly ,
@@ -850,7 +867,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
850
867
let cnum = self . maybe_resolve_crate (
851
868
dep. name ,
852
869
dep_kind,
853
- CrateOrigin :: IndirectDependency { dep_root, dep : & dep } ,
870
+ CrateOrigin :: IndirectDependency {
871
+ dep_root,
872
+ parent_private : parent_is_private,
873
+ dep : & dep,
874
+ } ,
854
875
) ?;
855
876
crate_num_map. push ( cnum) ;
856
877
}
0 commit comments