From: Richard Dodd Date: Sun, 15 Apr 2018 12:56:22 +0000 (+0100) Subject: [Wip] fix issue 5345 X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~67^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=466196959fd172bcef53dcd087d48e6716fc5bcb;p=cargo.git [Wip] fix issue 5345 --- diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 990144254..5f8d24d1e 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -196,6 +196,7 @@ impl hash::Hash for Package { } } +#[derive(Debug)] pub struct PackageSet<'cfg> { packages: HashMap>, sources: RefCell>, diff --git a/src/cargo/core/source/mod.rs b/src/cargo/core/source/mod.rs index 65380e207..b842a5792 100644 --- a/src/cargo/core/source/mod.rs +++ b/src/cargo/core/source/mod.rs @@ -1,4 +1,5 @@ use std::collections::hash_map::{HashMap, IterMut, Values}; +use std::fmt; use core::{Package, PackageId, Registry}; use util::CargoResult; @@ -78,6 +79,14 @@ pub struct SourceMap<'src> { map: HashMap>, } +// impl debug on source requires specialization, if even desirable at all +impl<'src> fmt::Debug for SourceMap<'src> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "SourceMap ")?; + f.debug_set().entries(self.map.keys()).finish() + } +} + /// A `std::collection::hash_map::Values` for `SourceMap` pub type Sources<'a, 'src> = Values<'a, SourceId, Box>; diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 647b639ab..3f2c93e88 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -7,11 +7,16 @@ use core::Workspace; use ops; use util::CargoResult; +/// Strongly typed options for the `cargo doc` command. +#[derive(Debug)] pub struct DocOptions<'a> { + /// Whether to attempt to open the browser after compiling the docs pub open_result: bool, + /// Options to pass through to the compiler pub compile_opts: ops::CompileOptions<'a>, } +/// Main method for `cargo doc`. pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { let specs = options.compile_opts.spec.into_package_id_specs(ws)?; let resolve = ops::resolve_ws_precisely( @@ -34,6 +39,7 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { let mut lib_names = HashMap::new(); let mut bin_names = HashMap::new(); + //println!("{:#?}", pkgs); for package in &pkgs { for target in package.targets().iter().filter(|t| t.documented()) { if target.is_lib() { @@ -61,6 +67,7 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { } ops::compile(ws, &options.compile_opts)?; + //println!("Made it!"); if options.open_result { let name = if pkgs.len() > 1 { diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index b1ea625fc..f81c37fbf 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1494,3 +1494,32 @@ fn doc_edition() { .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"), ); } + +// Tests an issue where depending on different versions of the same file caused `cargo doc` to +// fail. +#[test] +fn issue_5345() { + let foo = project("foo") + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [target.'cfg(all(windows, target_arch = "x86"))'.dependencies] + bar = "0.1" + + [target.'cfg(not(all(windows, target_arch = "x86")))'.dependencies] + bar = "0.2" + "#, + ) + .file("src/lib.rs", "extern crate bar;") + .build(); + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); + + assert_that(foo.cargo("build"), execs().with_status(0)); + assert_that(foo.cargo("doc"), execs().with_status(0)); +}