Skip to content

Commit 6a11d0b

Browse files
committed
Don't leak sysroot crates through dependencies
Previously if a dependency of the current crate depended on a sysroot crate, then extern crate would in the current crate would pick the first loaded version of said sysroot crate even in case of an ambiguity. This is surprising and brittle. For -Ldependency= we already blocked this, but the fix didn't account for sysroot crates.
1 parent 42ec52b commit 6a11d0b

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ impl CStore {
519519
externs: &Externs,
520520
name: Symbol,
521521
hash: Option<Svh>,
522-
kind: PathKind,
523522
) -> Option<CrateNum> {
524523
for (cnum, data) in self.iter_crate_data() {
525524
if data.name() != name {
@@ -561,27 +560,9 @@ impl CStore {
561560
continue;
562561
}
563562

564-
// Alright, so we've gotten this far which means that `data` has the
565-
// right name, we don't have a hash, and we don't have a --extern
566-
// pointing for ourselves. We're still not quite yet done because we
567-
// have to make sure that this crate was found in the crate lookup
568-
// path (this is a top-level dependency) as we don't want to
569-
// implicitly load anything inside the dependency lookup path.
570-
let prev_kind = source
571-
.dylib
572-
.as_ref()
573-
.or(source.rlib.as_ref())
574-
.or(source.rmeta.as_ref())
575-
.expect("No sources for crate")
576-
.1;
577-
if kind.matches(prev_kind) {
578-
return Some(cnum);
579-
} else {
580-
debug!(
581-
"failed to load existing crate {}; kind {:?} did not match prev_kind {:?}",
582-
name, kind, prev_kind
583-
);
584-
}
563+
// While the crate name matched, no --extern crate_name=path matched. It is possible
564+
// that we have already loaded the target crate, but if that happens CStore::load will
565+
// indicate so and we gracefully handle this, just potentially wasting a bit of time.
585566
}
586567

587568
None
@@ -818,9 +799,7 @@ impl CStore {
818799
let path_kind = if dep.is_some() { PathKind::Dependency } else { PathKind::Crate };
819800
let private_dep = origin.private_dep();
820801

821-
let result = if let Some(cnum) =
822-
self.existing_match(&tcx.sess.opts.externs, name, hash, path_kind)
823-
{
802+
let result = if let Some(cnum) = self.existing_match(&tcx.sess.opts.externs, name, hash) {
824803
(LoadResult::Previous(cnum), None)
825804
} else {
826805
info!("falling back to a load");

0 commit comments

Comments
 (0)