rustc: Fix a leak in dependency= paths #21113
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the addition of separate search paths to the compiler, it was intended that
applications such as Cargo could require a
--extern
flag perextern crate
directive in the source. The system can currently be subverted, however, due to
the
existing_match()
logic in the crate loader.When loading crates we first attempt to match an
extern crate
directiveagainst all previously loaded crates to avoid reading metadata twice. This "hit
the cache if possible" step was erroneously leaking crates across the search
path boundaries, however. For example:
If
b
depends ona
, then it will load cratea
when theextern crate b
directive is being processed. When the compiler reaches
extern crate a
it willuse the previously loaded version no matter what. If the compiler was not
invoked with
-L crate=path/to/a
, it will still succeed.This behavior is allowing
extern crate
declarations in Cargo without acorresponding declaration in the manifest of a dependency, which is considered
a bug.
This commit fixes this problem by keeping track of the origin search path for a
crate. Crates loaded from the dependency search path are not candidates for
crates which are loaded from the crate search path.