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

Fix BorrowMutError when calling cargo doc --open #9531

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,6 @@ use crate::core::{Shell, Workspace};
use crate::ops;
use crate::util::config::PathAndArgs;
use crate::util::CargoResult;
use serde::Deserialize;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
Expand All @@ -16,13 15,6 @@ pub struct DocOptions {
pub compile_opts: ops::CompileOptions,
}

#[derive(Deserialize)]
struct CargoDocConfig {
/// Browser to use to open docs. If this is unset, the value of the environment variable
/// `BROWSER` will be used.
browser: Option<PathAndArgs>,
}

/// Main method for `cargo doc`.
pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
let compilation = ops::compile(ws, &options.compile_opts)?;
Expand All @@ -35,15 27,14 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
.join(&name)
.join("index.html");
if path.exists() {
let config_browser = {
let cfg: Option<PathAndArgs> = ws.config().get("doc.browser")?;
cfg.map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args))
};

let mut shell = ws.config().shell();
shell.status("Opening", path.display())?;
let cfg = ws.config().get::<CargoDocConfig>("doc")?;
open_docs(
&path,
&mut shell,
cfg.browser
.map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args)),
)?;
open_docs(&path, &mut shell, config_browser)?;
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 1168,41 @@ fn doc_workspace_open_help_message() {
.run();
}

#[cargo_test]
#[cfg(not(windows))] // `echo` may not be available
fn doc_extern_map_local() {
if !is_nightly() {
// -Zextern-html-root-url is unstable
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
"#,
)
.file("src/lib.rs", "")
.file(".cargo/config.toml", "doc.extern-map.std = 'local'")
.build();

p.cargo("doc -v --no-deps -Zrustdoc-map --open")
.env("BROWSER", "echo")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[DOCUMENTING] foo v0.1.0 [..]
[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 0.1.0`
[FINISHED] [..]
Opening [CWD]/target/doc/foo/index.html
",
)
.run();
}

#[cargo_test]
#[cfg(not(windows))] // `echo` may not be available
fn doc_workspace_open_different_library_and_package_names() {
Expand Down