Skip to content

Commit

Permalink
Cleanly report when rust-docs isn't installed
Browse files Browse the repository at this point in the history
When the user runs `rustup doc` on a toolchain which doesn't
have the `rust-docs` component installed, we now report more
nicely that the user ought to try and install the component.

Fixes rust-lang#901

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Nov 10, 2019
1 parent 39f4f5f commit bb593bb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,19 @@ const DOCS_DATA: &[(&str, &str, &str,)] = &[

fn doc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
for cstatus in &toolchain.list_components()? {
if cstatus.component.short_name_in_manifest() == "rust-docs" && !cstatus.installed {
info!(
"`rust-docs` not installed in toolchain `{}`",
toolchain.name()
);
info!(
"To install, try `rustup component add --toolchain {} rust-docs`",
toolchain.name()
);
return Err("unable to view documentation which is not installed".into());
}
}
let topical_path: PathBuf;

let doc_url = if let Some(topic) = m.value_of("topic") {
Expand Down
13 changes: 13 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,19 @@ fn docs_topical_with_path() {
});
}

#[test]
fn docs_missing() {
setup(&|config| {
expect_ok(config, &["rustup", "set", "profile", "minimal"]);
expect_ok(config, &["rustup", "default", "nightly"]);
expect_err(
config,
&["rustup", "doc"],
"error: unable to view documentation which is not installed",
);
});
}

#[cfg(unix)]
#[test]
fn non_utf8_arg() {
Expand Down

0 comments on commit bb593bb

Please sign in to comment.