Skip to content

Commit e36020c

Browse files
committed
rustc_metadata: inherit dependency privacy flag
1 parent 64025bb commit e36020c

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
365365
lib: Library,
366366
dep_kind: CrateDepKind,
367367
name: Symbol,
368+
private_dep: bool,
368369
) -> Result<CrateNum, CrateError> {
369370
let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");
370371

@@ -518,15 +519,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
518519
if !name.as_str().is_ascii() {
519520
return Err(CrateError::NonAsciiName(name));
520521
}
521-
let (root, hash, host_hash, extra_filename, path_kind) = match dep {
522+
let (root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep {
522523
Some((root, dep)) => (
523524
Some(root),
524525
Some(dep.hash),
525526
dep.host_hash,
526527
Some(&dep.extra_filename[..]),
527528
PathKind::Dependency,
529+
dep.is_private,
528530
),
529-
None => (None, None, None, None, PathKind::Crate),
531+
None => (None, None, None, None, PathKind::Crate, false),
530532
};
531533
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
532534
(LoadResult::Previous(cnum), None)
@@ -562,10 +564,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
562564
dep_kind = CrateDepKind::MacrosOnly;
563565
}
564566
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
567+
data.update_private_dep(|private_dep| private_dep && private_dep);
565568
Ok(cnum)
566569
}
567570
(LoadResult::Loaded(library), host_library) => {
568-
self.register_crate(host_library, root, library, dep_kind, name)
571+
self.register_crate(host_library, root, library, dep_kind, name, private_dep)
569572
}
570573
_ => panic!(),
571574
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(crate) struct CrateMetadata {
113113
source: Lrc<CrateSource>,
114114
/// Whether or not this crate should be consider a private dependency
115115
/// for purposes of the 'exported_private_dependencies' lint
116-
private_dep: bool,
116+
private_dep: Lock<bool>,
117117
/// The hash for the host proc macro. Used to support `-Z dual-proc-macro`.
118118
host_hash: Option<Svh>,
119119

@@ -690,12 +690,13 @@ impl MetadataBlob {
690690
writeln!(out, "=External Dependencies=")?;
691691

692692
for (i, dep) in root.crate_deps.decode(self).enumerate() {
693-
let CrateDep { name, extra_filename, hash, host_hash, kind } = dep;
693+
let CrateDep { name, extra_filename, hash, host_hash, kind, is_private } = dep;
694694
let number = i + 1;
695695

696696
writeln!(
697697
out,
698-
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?}"
698+
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}",
699+
privacy = if is_private { "private" } else { "public" }
699700
)?;
700701
}
701702
write!(out, "\n")?;
@@ -1617,7 +1618,7 @@ impl CrateMetadata {
16171618
dependencies,
16181619
dep_kind: Lock::new(dep_kind),
16191620
source: Lrc::new(source),
1620-
private_dep,
1621+
private_dep: Lock::new(private_dep),
16211622
host_hash,
16221623
extern_crate: Lock::new(None),
16231624
hygiene_context: Default::default(),
@@ -1665,6 +1666,10 @@ impl CrateMetadata {
16651666
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
16661667
}
16671668

1669+
pub(crate) fn update_private_dep(&self, f: impl FnOnce(bool) -> bool) {
1670+
self.private_dep.with_lock(|private_dep| *private_dep = f(*private_dep))
1671+
}
1672+
16681673
pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {
16691674
self.root.required_panic_strategy
16701675
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ provide! { tcx, def_id, other, cdata,
285285
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
286286

287287
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
288-
is_private_dep => { cdata.private_dep }
288+
is_private_dep => {
289+
let r = *cdata.private_dep.lock();
290+
r
291+
}
289292
is_panic_runtime => { cdata.root.panic_runtime }
290293
is_compiler_builtins => { cdata.root.compiler_builtins }
291294
has_global_allocator => { cdata.root.has_global_allocator }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18801880
host_hash: self.tcx.crate_host_hash(cnum),
18811881
kind: self.tcx.dep_kind(cnum),
18821882
extra_filename: self.tcx.extra_filename(cnum).clone(),
1883+
is_private: self.tcx.is_private_dep(cnum),
18831884
};
18841885
(cnum, dep)
18851886
})

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub(crate) struct CrateDep {
302302
pub host_hash: Option<Svh>,
303303
pub kind: CrateDepKind,
304304
pub extra_filename: String,
305+
pub is_private: bool,
305306
}
306307

307308
#[derive(MetadataEncodable, MetadataDecodable)]

0 commit comments

Comments
 (0)