Skip to content

Commit 35c9242

Browse files
authored
Merge pull request #2116 from kinnison/kinnison/report-missing-docs
Cleanly report when rust-docs isn't installed
2 parents 39f4f5f + bb593bb commit 35c9242

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/cli/rustup_mode.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,19 @@ const DOCS_DATA: &[(&str, &str, &str,)] = &[
12771277

12781278
fn doc(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
12791279
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
1280+
for cstatus in &toolchain.list_components()? {
1281+
if cstatus.component.short_name_in_manifest() == "rust-docs" && !cstatus.installed {
1282+
info!(
1283+
"`rust-docs` not installed in toolchain `{}`",
1284+
toolchain.name()
1285+
);
1286+
info!(
1287+
"To install, try `rustup component add --toolchain {} rust-docs`",
1288+
toolchain.name()
1289+
);
1290+
return Err("unable to view documentation which is not installed".into());
1291+
}
1292+
}
12801293
let topical_path: PathBuf;
12811294

12821295
let doc_url = if let Some(topic) = m.value_of("topic") {

tests/cli-rustup.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,19 @@ fn docs_topical_with_path() {
16161616
});
16171617
}
16181618

1619+
#[test]
1620+
fn docs_missing() {
1621+
setup(&|config| {
1622+
expect_ok(config, &["rustup", "set", "profile", "minimal"]);
1623+
expect_ok(config, &["rustup", "default", "nightly"]);
1624+
expect_err(
1625+
config,
1626+
&["rustup", "doc"],
1627+
"error: unable to view documentation which is not installed",
1628+
);
1629+
});
1630+
}
1631+
16191632
#[cfg(unix)]
16201633
#[test]
16211634
fn non_utf8_arg() {

0 commit comments

Comments
 (0)