Skip to content

Commit 28b7747

Browse files
committed
rustc_metadata: inherit dependency privacy flag
1 parent 2664660 commit 28b7747

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
361361
lib: Library,
362362
dep_kind: CrateDepKind,
363363
name: Symbol,
364+
private_dep: bool,
364365
) -> Result<CrateNum, CrateError> {
365366
let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");
366367

@@ -369,7 +370,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
369370
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
370371

371372
let private_dep =
372-
self.sess.opts.externs.get(name.as_str()).map_or(false, |e| e.is_private_dep);
373+
self.sess.opts.externs.get(name.as_str()).map_or(private_dep, |e| e.is_private_dep);
373374

374375
// Claim this crate number and cache it
375376
let cnum = self.cstore.intern_stable_crate_id(&crate_root)?;
@@ -514,15 +515,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
514515
if !name.as_str().is_ascii() {
515516
return Err(CrateError::NonAsciiName(name));
516517
}
517-
let (root, hash, host_hash, extra_filename, path_kind) = match dep {
518+
let (root, hash, host_hash, extra_filename, path_kind, private_dep) = match dep {
518519
Some((root, dep)) => (
519520
Some(root),
520521
Some(dep.hash),
521522
dep.host_hash,
522523
Some(&dep.extra_filename[..]),
523524
PathKind::Dependency,
525+
dep.is_private,
524526
),
525-
None => (None, None, None, None, PathKind::Crate),
527+
None => (None, None, None, None, PathKind::Crate, false),
526528
};
527529
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
528530
(LoadResult::Previous(cnum), None)
@@ -558,10 +560,11 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
558560
dep_kind = CrateDepKind::MacrosOnly;
559561
}
560562
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
563+
data.update_private_dep(|private_dep| private_dep && private_dep);
561564
Ok(cnum)
562565
}
563566
(LoadResult::Loaded(library), host_library) => {
564-
self.register_crate(host_library, root, library, dep_kind, name)
567+
self.register_crate(host_library, root, library, dep_kind, name, private_dep)
565568
}
566569
_ => panic!(),
567570
}

compiler/rustc_metadata/src/rmeta/decoder.rs

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

@@ -692,12 +692,13 @@ impl MetadataBlob {
692692
writeln!(out, "=External Dependencies=")?;
693693

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

698698
writeln!(
699699
out,
700-
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?}"
700+
"{number} {name}{extra_filename} hash {hash} host_hash {host_hash:?} kind {kind:?} {privacy}",
701+
privacy = if is_private { "private" } else { "public" }
701702
)?;
702703
}
703704
write!(out, "\n")?;
@@ -1610,7 +1611,7 @@ impl CrateMetadata {
16101611
dependencies,
16111612
dep_kind: Lock::new(dep_kind),
16121613
source: Lrc::new(source),
1613-
private_dep,
1614+
private_dep: Lock::new(private_dep),
16141615
host_hash,
16151616
extern_crate: Lock::new(None),
16161617
hygiene_context: Default::default(),
@@ -1658,6 +1659,10 @@ impl CrateMetadata {
16581659
self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
16591660
}
16601661

1662+
pub(crate) fn update_private_dep(&self, f: impl FnOnce(bool) -> bool) {
1663+
self.private_dep.with_lock(|private_dep| *private_dep = f(*private_dep))
1664+
}
1665+
16611666
pub(crate) fn required_panic_strategy(&self) -> Option<PanicStrategy> {
16621667
self.root.required_panic_strategy
16631668
}

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

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

288288
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
289-
is_private_dep => { cdata.private_dep }
289+
is_private_dep => {
290+
let r = *cdata.private_dep.lock();
291+
r
292+
}
290293
is_panic_runtime => { cdata.root.panic_runtime }
291294
is_compiler_builtins => { cdata.root.compiler_builtins }
292295
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
@@ -1863,6 +1863,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18631863
host_hash: self.tcx.crate_host_hash(cnum),
18641864
kind: self.tcx.dep_kind(cnum),
18651865
extra_filename: self.tcx.extra_filename(cnum).clone(),
1866+
is_private: self.tcx.is_private_dep(cnum),
18661867
};
18671868
(cnum, dep)
18681869
})

compiler/rustc_metadata/src/rmeta/mod.rs

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

306307
#[derive(MetadataEncodable, MetadataDecodable)]

0 commit comments

Comments
 (0)