Fix renaming crates as they come from 2 sources
authorAlex Crichton <alex@alexcrichton.com>
Wed, 25 Apr 2018 17:41:33 +0000 (10:41 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 27 Apr 2018 17:48:34 +0000 (10:48 -0700)
commitce5bbbc7d6898e1ccee3f7f4e20596c91f24fe49
tree6f1319d112208f37a2db6985bd7f44d0a582f5e7
parentd998906598f3ba790b230ce74993a64b553ce699
Fix renaming crates as they come from 2 sources

Previously there was a verification in manifest parsing that the same dependency
must come from the same source, but this erroneously triggered an error to get
emitted when the `package` key was used to rename crates. The first change here
was to update that clause to key off the `rename` field rather than the `name`
field.

Afterwards, though, this exposed an existing bug in the implementation. During
compilation we have a `Resolve` which is a graph of crates, but we don't know
*why* each edge in the dependency graph exists. In other words we don't know,
when looking at an edge of the graph, what `Dependency` caused that edge to be
drawn. We need to know this when passing `--extern` flags because the
`Dependency` is what lists what's being renamed.

This commit then primarily refactors `Resolve::deps` from an iterator of package
ids to an iterator of a tuples. The first element is the package id from before
and the second element is a list of `Dependency` directives which caused the
edge to ber driven.

This refactoring cleaned up a few places in the backend where we had to work
around the lack of this knowledge. Namely this also fixes the extra test added
here.

Closes #5413
14 files changed:
src/cargo/core/compiler/context/unit_dependencies.rs
src/cargo/core/compiler/mod.rs
src/cargo/core/resolver/context.rs
src/cargo/core/resolver/encode.rs
src/cargo/core/resolver/mod.rs
src/cargo/core/resolver/resolve.rs
src/cargo/core/resolver/types.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_fetch.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_output_metadata.rs
src/cargo/util/graph.rs
src/cargo/util/toml/mod.rs
tests/testsuite/rename_deps.rs