diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 640f2d9e381..9e868c2064f 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -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; @@ -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, -} - /// Main method for `cargo doc`. pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { let compilation = ops::compile(ws, &options.compile_opts)?; @@ -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 = 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::("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)?; } } diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 1dcf7735b6d..bb949b63a9f 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -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() {