Skip to content

Commit 0ca70be

Browse files
committed
rustc_metadata: fix private_dep logic in register_crate
1 parent 3740243 commit 0ca70be

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

compiler/rustc_metadata/src/creader.rs

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

372372
let Library { source, metadata } = lib;
373373
let crate_root = metadata.get_root();
374374
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
375375

376-
let private_dep =
377-
self.sess.opts.externs.get(name.as_str()).is_some_and(|e| e.is_private_dep);
376+
let private_dep = self
377+
.sess
378+
.opts
379+
.externs
380+
.get(name.as_str())
381+
.map_or(private_dep.unwrap_or(false), |e| e.is_private_dep)
382+
&& private_dep.unwrap_or(true);
378383

379384
// Claim this crate number and cache it
380385
let cnum = self.cstore.intern_stable_crate_id(&crate_root)?;
@@ -526,9 +531,9 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
526531
dep.host_hash,
527532
Some(&dep.extra_filename[..]),
528533
PathKind::Dependency,
529-
dep.is_private,
534+
Some(dep.is_private),
530535
),
531-
None => (None, None, None, None, PathKind::Crate, false),
536+
None => (None, None, None, None, PathKind::Crate, None),
532537
};
533538
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
534539
(LoadResult::Previous(cnum), None)
@@ -564,7 +569,9 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
564569
dep_kind = CrateDepKind::MacrosOnly;
565570
}
566571
data.update_dep_kind(|data_dep_kind| cmp::max(data_dep_kind, dep_kind));
567-
data.update_private_dep(|p_d| p_d && private_dep);
572+
if let Some(private_dep) = private_dep {
573+
data.update_private_dep(|p_d| p_d && private_dep);
574+
}
568575
Ok(cnum)
569576
}
570577
(LoadResult::Loaded(library), host_library) => {

0 commit comments

Comments
 (0)