Skip to content

Commit 5325497

Browse files
Evan Weilerkinnison
authored andcommitted
Add error message to indicate that a missing command is not available on the current toolchain
1 parent 0749f0a commit 5325497

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ error_chain! {
308308
description("toolchain does not contain binary")
309309
display("'{}' is not installed for the toolchain '{}'{}", bin, t, install_msg(bin, t, *is_default))
310310
}
311+
BinaryProvidedByUnavailableComponent(component: String, bin: String, toolchain: String) {
312+
description("binary is provided by a component which is not available in current toolchain")
313+
display("the '{}' component which provides the command '{}' is not available for the '{}' toolchain", component, bin, toolchain)
314+
}
311315
NeedMetadataUpgrade {
312316
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
313317
}

src/toolchain.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::component_for_bin;
12
use crate::config::Cfg;
23
use crate::dist::dist::TargetTriple;
34
use crate::dist::dist::ToolchainDesc;
@@ -274,6 +275,30 @@ impl<'a> InstalledCommonToolchain<'a> {
274275
.and_then(|s| s.parse().ok())
275276
.unwrap_or(0);
276277
if recursion_count > env_var::RUST_RECURSION_COUNT_MAX - 1 {
278+
let binary_lossy: String = binary.to_string_lossy().into();
279+
if let Ok(distributable) = DistributableToolchain::new(self.0) {
280+
if let (Some(component_name), Ok(component_statuses), Ok(Some(manifest))) = (
281+
component_for_bin(&binary_lossy),
282+
distributable.list_components(),
283+
distributable.get_manifest(),
284+
) {
285+
let component_status = component_statuses
286+
.iter()
287+
.find(|cs| cs.component.short_name(&manifest) == component_name)
288+
.expect(&format!(
289+
"component {} should be in the manifest",
290+
component_name
291+
));
292+
if !component_status.available {
293+
return Err(ErrorKind::BinaryProvidedByUnavailableComponent(
294+
component_status.component.short_name(&manifest),
295+
binary_lossy,
296+
self.0.name.clone(),
297+
)
298+
.into());
299+
}
300+
}
301+
}
277302
let defaults = self.0.cfg.get_default()?;
278303
return Err(ErrorKind::BinaryNotFound(
279304
binary.to_string_lossy().into(),

0 commit comments

Comments
 (0)