diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index a61e9c25cca..1c332b422db 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -39,6 +39,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { let mut lib_names = HashMap::new(); let mut bin_names = HashMap::new(); + let mut names = Vec::new(); for package in &pkgs { for target in package.targets().iter().filter(|t| t.documented()) { if target.is_lib() { @@ -62,27 +63,16 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> { package ); } + names.push(target.crate_name()); } } ops::compile(ws, &options.compile_opts)?; if options.open_result { - let name = if pkgs.len() > 1 { - failure::bail!( - "Passing multiple packages and `open` is not supported.\n\ - Please re-run this command with `-p ` where `` \ - is one of the following:\n {}", - pkgs.iter() - .map(|p| p.name().as_str()) - .collect::>() - .join("\n ") - ); - } else { - match lib_names.keys().chain(bin_names.keys()).nth(0) { - Some(s) => s.to_string(), - None => return Ok(()), - } + let name = match names.first() { + Some(s) => s.to_string(), + None => return Ok(()), }; // Don't bother locking here as if this is getting deleted there's diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 642cc07bd5d..f821eed090d 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1012,6 +1012,7 @@ fn doc_all_member_dependency_same_name() { } #[test] +#[cfg(not(any(target_os = "windows", target_os = "macos")))] fn doc_workspace_open_help_message() { let p = project() .file( @@ -1029,19 +1030,10 @@ fn doc_workspace_open_help_message() { // The order in which bar is compiled or documented is not deterministic p.cargo("doc --all --open") - .with_status(101) + .env("BROWSER", "echo") .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") - .with_stderr_contains( - "error: Passing multiple packages and `open` \ - is not supported.", - ) - .with_stderr_contains( - "Please re-run this command with `-p ` \ - where `` is one of the following:", - ) - .with_stderr_contains(" foo") - .with_stderr_contains(" bar") + .with_stderr_contains("[..] Opening [..]/foo/index.html") .run(); }