Skip to content

Commit 30bf81b

Browse files
committed
Auto merge of #5361 - derekdreery:issue_5345, r=matklad
Fix issue 5345 Fixes #5345. Also adds some docs and Debug impls.
2 parents de23b54 + d70f91e commit 30bf81b

File tree

8 files changed

+50
-2
lines changed

8 files changed

+50
-2
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
433433
self.unit_dependencies[unit].clone()
434434
}
435435

436+
/// Whether a dependency should be compiled for the host or target platform,
437+
/// specified by `Kind`.
436438
fn dep_platform_activated(&self, dep: &Dependency, kind: Kind) -> bool {
437439
// If this dependency is only available for certain platforms,
438440
// make sure we're only enabling it for that platform.

src/cargo/core/compiler/context/unit_dependencies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn compute_deps_doc<'a, 'cfg>(
209209
unit.pkg
210210
.dependencies()
211211
.iter()
212-
.filter(|d| d.name() == dep.name())
212+
.filter(|d| d.name() == dep.name() && d.version_req().matches(dep.version()))
213213
.any(|dep| match dep.kind() {
214214
DepKind::Normal => cx.dep_platform_activated(dep, unit.kind),
215215
_ => false,

src/cargo/core/package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ impl hash::Hash for Package {
198198
}
199199
}
200200

201+
#[derive(Debug)]
201202
pub struct PackageSet<'cfg> {
202203
packages: HashMap<PackageId, LazyCell<Package>>,
203204
sources: RefCell<SourceMap<'cfg>>,

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use self::types::{RcVecIter, RegistryQueryer};
6868

6969
pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
7070
pub use self::encode::{Metadata, WorkspaceResolve};
71-
pub use self::resolve::Resolve;
71+
pub use self::resolve::{Resolve, Deps, DepsNotReplaced};
7272
pub use self::types::Method;
7373

7474
mod context;

src/cargo/core/source/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::hash_map::{HashMap, IterMut, Values};
2+
use std::fmt;
23

34
use core::{Package, PackageId, Registry};
45
use util::CargoResult;
@@ -78,6 +79,14 @@ pub struct SourceMap<'src> {
7879
map: HashMap<SourceId, Box<Source + 'src>>,
7980
}
8081

82+
// impl debug on source requires specialization, if even desirable at all
83+
impl<'src> fmt::Debug for SourceMap<'src> {
84+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85+
write!(f, "SourceMap ")?;
86+
f.debug_set().entries(self.map.keys()).finish()
87+
}
88+
}
89+
8190
/// A `std::collection::hash_map::Values` for `SourceMap`
8291
pub type Sources<'a, 'src> = Values<'a, SourceId, Box<Source + 'src>>;
8392

src/cargo/ops/cargo_compile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub fn compile<'a>(
199199
compile_with_exec(ws, options, Arc::new(DefaultExecutor))
200200
}
201201

202+
/// Like `compile` but allows specifing a custom `Executor` that will be able to intercept build
203+
/// calls and add custom logic. `compile` uses `DefaultExecutor` which just passes calls through.
202204
pub fn compile_with_exec<'a>(
203205
ws: &Workspace<'a>,
204206
options: &CompileOptions<'a>,

src/cargo/ops/cargo_doc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ use core::Workspace;
77
use ops;
88
use util::CargoResult;
99

10+
/// Strongly typed options for the `cargo doc` command.
11+
#[derive(Debug)]
1012
pub struct DocOptions<'a> {
13+
/// Whether to attempt to open the browser after compiling the docs
1114
pub open_result: bool,
15+
/// Options to pass through to the compiler
1216
pub compile_opts: ops::CompileOptions<'a>,
1317
}
1418

19+
/// Main method for `cargo doc`.
1520
pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
1621
let specs = options.compile_opts.spec.into_package_id_specs(ws)?;
1722
let resolve = ops::resolve_ws_precisely(

tests/testsuite/doc.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,3 +1494,32 @@ fn doc_edition() {
14941494
.with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
14951495
);
14961496
}
1497+
1498+
// Tests an issue where depending on different versions of the same crate depending on `cfg`s
1499+
// caused `cargo doc` to fail.
1500+
#[test]
1501+
fn issue_5345() {
1502+
let foo = project("foo")
1503+
.file(
1504+
"Cargo.toml",
1505+
r#"
1506+
[package]
1507+
name = "foo"
1508+
version = "0.0.1"
1509+
authors = []
1510+
1511+
[target.'cfg(all(windows, target_arch = "x86"))'.dependencies]
1512+
bar = "0.1"
1513+
1514+
[target.'cfg(not(all(windows, target_arch = "x86")))'.dependencies]
1515+
bar = "0.2"
1516+
"#,
1517+
)
1518+
.file("src/lib.rs", "extern crate bar;")
1519+
.build();
1520+
Package::new("bar", "0.1.0").publish();
1521+
Package::new("bar", "0.2.0").publish();
1522+
1523+
assert_that(foo.cargo("build"), execs().with_status(0));
1524+
assert_that(foo.cargo("doc"), execs().with_status(0));
1525+
}

0 commit comments

Comments
 (0)