Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple crates with the same name lead to conflicting target/doc/crate directories #56169

Open
jturner314 opened this issue Nov 22, 2018 · 1 comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jturner314
Copy link
Contributor

The new rename-dependency feature in Rust 1.31 makes it possible to depend on multiple versions of the same crate. This mostly works fine, but when building docs, the docs of one version overwrite the docs of the other version.

I'm working on adding support for converting arrays from the nalgebra crate to the ndarray crate, and I'd like this to work for multiple versions of nalgebra. So, I've added this to the Cargo.toml of ndarray:

[dependencies]
nalgebra-crate-0_15 = { package = "nalgebra", version = "0.15", optional = true }
nalgebra-crate-0_16 = { package = "nalgebra", version = "0.16", optional = true }

[features]
nalgebra-0_15 = ["nalgebra-crate-0_15"]
nalgebra-0_16 = ["nalgebra-crate-0_16"]

In lib.rs, the features are used for conditional compilation:

#[cfg(feature = "nalgebra-0_15")]
extern crate nalgebra_crate_0_15;
#[cfg(feature = "nalgebra-0_16")]
extern crate nalgebra_crate_0_16;

#[cfg(feature = "nalgebra-0_15")]
mod convert_nalgebra_0_15;
#[cfg(feature = "nalgebra-0_16")]
mod convert_nalgebra_0_16;

and the convert_nalgebra_0_15 and convert_nalgebra_0_16 modules implement the conversions. For example, convert_nalgebra_0_15 contains

use imp_prelude::*;
use nalgebra_crate_0_15 as na;

/// **Requires crate feature `"nalgebra-0_15"`**
impl<A, R, S1, S2> From<na::Matrix<A, R, na::U1, S1>> for ArrayBase<S2, Ix1>
where
    A: na::Scalar,
    R: na::Dim,
    S1: na::storage::Storage<A, R, na::U1>,
    S2: DataOwned<Elem = A>,
{
    fn from(vector: na::Matrix<A, R, na::U1, S1>) -> ArrayBase<S2, Ix1> {
        ArrayBase::from_vec(vector.iter().cloned().collect())
    }
}

// ...

(See the full changes here.)

When I build with cargo +nightly doc --open --features=nalgebra-0_15,nalgebra-0_16, I see both implementations as expected in docs of the ndarray crate:

docs

The problem is that both versions of the docs of nalgebra are written to the same location, target/doc/nalgebra. So, for example, when I click on Matrix (a type defined in the nalgebra crate), I get taken to target/doc/nalgebra/base/struct.Matrix.html regardless of which version of nalgebra it corresponds to.

To fix this, I would suggest naming the documentation directories according to the names the crates were renamed to. So, there would be target/doc/nalgebra-crate-0_15 and target/doc/nalgebra-crate-0_16 directories instead of just a single target/doc/nalgebra directory.

Meta

rustup run nightly rustc --version --verbose:

rustc 1.32.0-nightly (f1e2fa8f0 2018-11-20)
binary: rustc
commit-hash: f1e2fa8f0469aac1ea69dd5b6164e1d198d57934
commit-date: 2018-11-20
host: x86_64-unknown-linux-gnu
release: 1.32.0-nightly
LLVM version: 8.0
@jonas-schievink jonas-schievink added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 27, 2019
bors added a commit to rust-lang/cargo that referenced this issue Jun 3, 2019
Catch filename output collisions in rustdoc.

This does some general cleanup so that rustdoc output is computed correctly.  This allows the collision detection code to work.  There are some known issues with rustdoc creating collisions (rust-lang/rust#61378, rust-lang/rust#56169).  This is related to issue #6313.

This includes a change that `CompileMode::is_doc` no longer returns `true` for doc tests. This has bothered me for a while, as various points in the code was not handling it correctly. Separating it into `is_doc` and `is_doc_test` I think is better and more explicit.

Note for reviewing: There is a big diff in `calc_outputs`, but this is just rearranging code. Everything in `calc_outputs_rustc` is unchanged from the original.

The only functional changes should be:
- A warning is emitted for colliding rustdoc output.
- Don't create an empty fingerprint directory for doc tests.
@SimonSapin SimonSapin changed the title Docs with rename-dependency and depending on multiple versions of the same crate lead to conflicting target/doc/crate directories Multiple crates with the same name lead to conflicting target/doc/crate directories Jun 25, 2019
@SimonSapin
Copy link
Contributor

This can also happen without rename-dependency, though an intermediate dependency. For example the lock file for this repository currently involves two versions of winapi:

rust/Cargo.lock

Lines 4568 to 4569 in 303f77e

"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants