Skip to content

Commit e814458

Browse files
rami3ldjc
authored andcommitted
Delete suggestions of removing the relevant component from component_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.
1 parent c5f0316 commit e814458

File tree

2 files changed

+76
-55
lines changed

2 files changed

+76
-55
lines changed

src/dist/manifestation/tests.rs

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,17 @@ fn unavailable_component() {
772772
)
773773
.unwrap_err();
774774
match err.downcast::<RustupError>() {
775-
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
776-
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus"));
775+
Ok(RustupError::RequestedComponentsUnavailable {
776+
components,
777+
manifest,
778+
toolchain,
779+
}) => {
780+
assert_eq!(toolchain, "nightly");
781+
let descriptions = components
782+
.iter()
783+
.map(|c| c.description(&manifest))
784+
.collect::<Vec<_>>();
785+
assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"])
777786
}
778787
_ => panic!(),
779788
}
@@ -833,8 +842,17 @@ fn unavailable_component_from_profile() {
833842
)
834843
.unwrap_err();
835844
match err.downcast::<RustupError>() {
836-
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
837-
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc"));
845+
Ok(RustupError::RequestedComponentsUnavailable {
846+
components,
847+
manifest,
848+
toolchain,
849+
}) => {
850+
assert_eq!(toolchain, "nightly");
851+
let descriptions = components
852+
.iter()
853+
.map(|c| c.description(&manifest))
854+
.collect::<Vec<_>>();
855+
assert_eq!(descriptions, ["'rustc' for target 'x86_64-apple-darwin'"])
838856
}
839857
_ => panic!(),
840858
}
@@ -913,8 +931,17 @@ fn removed_component() {
913931
)
914932
.unwrap_err();
915933
match err.downcast::<RustupError>() {
916-
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
917-
assert!(e.to_string().contains("rustup component remove --toolchain nightly --target x86_64-apple-darwin bonus"));
934+
Ok(RustupError::RequestedComponentsUnavailable {
935+
components,
936+
manifest,
937+
toolchain,
938+
}) => {
939+
assert_eq!(toolchain, "nightly");
940+
let descriptions = components
941+
.iter()
942+
.map(|c| c.description(&manifest))
943+
.collect::<Vec<_>>();
944+
assert_eq!(descriptions, ["'bonus' for target 'x86_64-apple-darwin'"])
918945
}
919946
_ => panic!(),
920947
}
@@ -992,13 +1019,24 @@ fn unavailable_components_is_target() {
9921019
)
9931020
.unwrap_err();
9941021
match err.downcast::<RustupError>() {
995-
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
996-
let err_str = e.to_string();
997-
assert!(err_str
998-
.contains("rustup target remove --toolchain nightly i686-apple-darwin"));
999-
assert!(err_str.contains(
1000-
"rustup target remove --toolchain nightly i686-unknown-linux-gnu"
1001-
));
1022+
Ok(RustupError::RequestedComponentsUnavailable {
1023+
components,
1024+
manifest,
1025+
toolchain,
1026+
}) => {
1027+
assert_eq!(toolchain, "nightly");
1028+
let descriptions = components
1029+
.iter()
1030+
.map(|c| c.description(&manifest))
1031+
.collect::<Vec<_>>();
1032+
assert_eq!(
1033+
descriptions,
1034+
[
1035+
"'rust-std' for target 'x86_64-apple-darwin'",
1036+
"'rust-std' for target 'i686-apple-darwin'",
1037+
"'rust-std' for target 'i686-unknown-linux-gnu'"
1038+
]
1039+
);
10021040
}
10031041
_ => panic!(),
10041042
}
@@ -1071,13 +1109,23 @@ fn unavailable_components_with_same_target() {
10711109
)
10721110
.unwrap_err();
10731111
match err.downcast::<RustupError>() {
1074-
Ok(e @ RustupError::RequestedComponentsUnavailable { .. }) => {
1075-
let err_str = e.to_string();
1076-
assert!(err_str
1077-
.contains("rustup target remove --toolchain nightly x86_64-apple-darwin"));
1078-
assert!(err_str.contains(
1079-
"rustup component remove --toolchain nightly --target x86_64-apple-darwin rustc"
1080-
));
1112+
Ok(RustupError::RequestedComponentsUnavailable {
1113+
components,
1114+
manifest,
1115+
toolchain,
1116+
}) => {
1117+
assert_eq!(toolchain, "nightly");
1118+
let descriptions = components
1119+
.iter()
1120+
.map(|c| c.description(&manifest))
1121+
.collect::<Vec<_>>();
1122+
assert_eq!(
1123+
descriptions,
1124+
[
1125+
"'rustc' for target 'x86_64-apple-darwin'",
1126+
"'rust-std' for target 'x86_64-apple-darwin'"
1127+
]
1128+
);
10811129
}
10821130
_ => panic!(),
10831131
}

src/errors.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,6 @@ fn suggest_message(suggestion: &Option<String>) -> String {
147147
}
148148
}
149149

150-
fn remove_component_msg(cs: &Component, manifest: &Manifest, toolchain: &str) -> String {
151-
if cs.short_name_in_manifest() == "rust-std" {
152-
// We special-case rust-std as it's the stdlib so really you want to do
153-
// rustup target remove
154-
format!(
155-
" rustup target remove --toolchain {} {}",
156-
toolchain,
157-
cs.target.as_deref().unwrap_or(toolchain)
158-
)
159-
} else {
160-
format!(
161-
" rustup component remove --toolchain {}{} {}",
162-
toolchain,
163-
if let Some(target) = cs.target.as_ref() {
164-
format!(" --target {target}")
165-
} else {
166-
String::default()
167-
},
168-
cs.short_name(manifest)
169-
)
170-
}
171-
}
172-
173150
fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String {
174151
assert!(!cs.is_empty());
175152

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

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

215-
let remove_msg = cs
216-
.iter()
217-
.map(|c| remove_component_msg(c, manifest, toolchain))
218-
.collect::<Vec<_>>()
219-
.join("\n");
220187
let _ = write!(
221188
buf,
222-
"some components unavailable for download for channel '{toolchain}': {cs_str}\n\
223-
If you don't need the components, you can remove them with:\n\n{remove_msg}\n\n{TOOLSTATE_MSG}",
189+
"some components unavailable for download for channel '{toolchain}': {cs_str}",
224190
);
191+
192+
if toolchain.starts_with("nightly") {
193+
let _ = write!(
194+
buf,
195+
"Sometimes not all components are available in any given nightly. "
196+
);
197+
}
225198
}
226199

227200
String::from_utf8(buf).unwrap()

0 commit comments

Comments
 (0)