Skip to content

Commit

Permalink
Delete suggestions of removing the relevant component from `component…
Browse files Browse the repository at this point in the history
…_unavailable_msg`

After digging into the codebase, I realized that the message generated
by `component_unavailable_msg` is used only when:

- Some components are missing from the toolchain so that the
  installation can no longer proceed;
- We are not installing these components as a part of a
  toolchain-wide operation (e.g. updating the existing `nightly`),
  which is covered by `components_missing_msg` by catching the
  `RustupError::RequestedComponentsUnavailable` and re-throwing
  it as a `DistError::ToolchainComponentsMissing`
  (see <#3453 (comment)>
  for more info).

Thus, I decided to remove the `rustup component remove` suggestion
altogether.
  • Loading branch information
rami3l authored and djc committed Oct 26, 2023
1 parent c5f0316 commit e814458
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 55 deletions.
88 changes: 68 additions & 20 deletions src/dist/manifestation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,17 @@ fn unavailable_component() {
)
.unwrap_err();
match err.downcast::<RustupError>() {
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus"));
Ok(RustupError::RequestedComponentsUnavailable {
components,
manifest,
toolchain,
}) => {
assert_eq!(toolchain, "nightly");
let descriptions = components
.iter()
.map(|c| c.description(&manifest))
.collect::<Vec<_>>();
assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"])
}
_ => panic!(),
}
Expand Down Expand Up @@ -833,8 +842,17 @@ fn unavailable_component_from_profile() {
)
.unwrap_err();
match err.downcast::<RustupError>() {
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc"));
Ok(RustupError::RequestedComponentsUnavailable {
components,
manifest,
toolchain,
}) => {
assert_eq!(toolchain, "nightly");
let descriptions = components
.iter()
.map(|c| c.description(&manifest))
.collect::<Vec<_>>();
assert_eq!(descriptions, ["'rustc' for target 'x86_64-apple-darwin'"])
}
_ => panic!(),
}
Expand Down Expand Up @@ -913,8 +931,17 @@ fn removed_component() {
)
.unwrap_err();
match err.downcast::<RustupError>() {
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus"));
Ok(RustupError::RequestedComponentsUnavailable {
components,
manifest,
toolchain,
}) => {
assert_eq!(toolchain, "nightly");
let descriptions = components
.iter()
.map(|c| c.description(&manifest))
.collect::<Vec<_>>();
assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"])
}
_ => panic!(),
}
Expand Down Expand Up @@ -992,13 +1019,24 @@ fn unavailable_components_is_target() {
)
.unwrap_err();
match err.downcast::<RustupError>() {
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
let err_str = e.to_string();
assert!(err_str
.contains("rustup target remove --toolchain nightly i686-apple-darwin"));
assert!(err_str.contains(
"rustup target remove --toolchain nightly i686-unknown-linux-gnu"
));
Ok(RustupError::RequestedComponentsUnavailable {
components,
manifest,
toolchain,
}) => {
assert_eq!(toolchain, "nightly");
let descriptions = components
.iter()
.map(|c| c.description(&manifest))
.collect::<Vec<_>>();
assert_eq!(
descriptions,
[
"'rust-std' for target 'x86_64-apple-darwin'",
"'rust-std' for target 'i686-apple-darwin'",
"'rust-std' for target 'i686-unknown-linux-gnu'"
]
);
}
_ => panic!(),
}
Expand Down Expand Up @@ -1071,13 +1109,23 @@ fn unavailable_components_with_same_target() {
)
.unwrap_err();
match err.downcast::<RustupError>() {
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
let err_str = e.to_string();
assert!(err_str
.contains("rustup target remove --toolchain nightly x86_64-apple-darwin"));
assert!(err_str.contains(
"rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc"
));
Ok(RustupError::RequestedComponentsUnavailable {
components,
manifest,
toolchain,
}) => {
assert_eq!(toolchain, "nightly");
let descriptions = components
.iter()
.map(|c| c.description(&manifest))
.collect::<Vec<_>>();
assert_eq!(
descriptions,
[
"'rustc' for target 'x86_64-apple-darwin'",
"'rust-std' for target 'x86_64-apple-darwin'"
]
);
}
_ => panic!(),
}
Expand Down
43 changes: 8 additions & 35 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,6 @@ fn suggest_message(suggestion: &Option<String>) -> String {
}
}

fn remove_component_msg(cs: &Component, manifest: &Manifest, toolchain: &str) -> String {
if cs.short_name_in_manifest() == "rust-std" {
// We special-case rust-std as it's the stdlib so really you want to do
// rustup target remove
format!(
" rustup target remove --toolchain {} {}",
toolchain,
cs.target.as_deref().unwrap_or(toolchain)
)
} else {
format!(
" rustup component remove --toolchain {}{} {}",
toolchain,
if let Some(target) = cs.target.as_ref() {
format!(" --target {target}")
} else {
String::default()
},
cs.short_name(manifest)
)
}
}

fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String {
assert!(!cs.is_empty());

Expand All @@ -188,11 +165,6 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
"Sometimes not all components are available in any given nightly. "
);
}
let _ = write!(
buf,
"If you don't need the component, you can remove it with:\n\n{}",
remove_component_msg(&cs[0], manifest, toolchain)
);
} else {
// More than one component

Expand All @@ -212,16 +184,17 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
.join(", ")
};

let remove_msg = cs
.iter()
.map(|c| remove_component_msg(c, manifest, toolchain))
.collect::<Vec<_>>()
.join("\n");
let _ = write!(
buf,
"some components unavailable for download for channel '{toolchain}': {cs_str}\n\
If you don't need the components, you can remove them with:\n\n{remove_msg}\n\n{TOOLSTATE_MSG}",
"some components unavailable for download for channel '{toolchain}': {cs_str}",
);

if toolchain.starts_with("nightly") {
let _ = write!(
buf,
"Sometimes not all components are available in any given nightly. "
);
}
}

String::from_utf8(buf).unwrap()
Expand Down

0 comments on commit e814458

Please sign in to comment.