Skip to content

Commit 355852a

Browse files
committed
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 <rust-lang#3453 (comment)> for more info). Thus, I decided to remove the `rustup component remove` suggestion altogether.
1 parent aa652b8 commit 355852a

2 files changed

Lines changed: 109 additions & 95 deletions

File tree

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: 41 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ use crate::{
1919
toolchain::names::{PathBasedToolchainName, ToolchainName},
2020
};
2121

22-
const TOOLSTATE_MSG: &str =
23-
"If you require these components, please install and use the latest successful build version,\n\
24-
which you can find at <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
25-
the correct date, install it with a command such as:\n\n \
26-
rustup toolchain install nightly-2018-12-27\n\n\
27-
Then you can use the toolchain with commands such as:\n\n \
28-
cargo +nightly-2018-12-27 build";
29-
3022
/// A type erasing thunk for the retry crate to permit use with anyhow. See <https://github.com/dtolnay/anyhow/issues/149>
3123
#[derive(Debug, ThisError)]
3224
#[error(transparent)]
@@ -147,29 +139,6 @@ fn suggest_message(suggestion: &Option<String>) -> String {
147139
}
148140
}
149141

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-
173142
/// Returns a error message indicating that certain [`Component`]s are unavailable.
174143
///
175144
/// See also [`component_missing_msg`](../dist/dist/fn.components_missing_msg.html)
@@ -178,57 +147,54 @@ fn remove_component_msg(cs: &Component, manifest: &Manifest, toolchain: &str) ->
178147
/// # Panics
179148
/// This function will panic when the collection of unavailable components `cs` is empty.
180149
fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &str) -> String {
181-
assert!(!cs.is_empty());
182-
183150
let mut buf = vec![];
184-
185-
if cs.len() == 1 {
186-
let _ = writeln!(
187-
buf,
188-
"component {} is unavailable for download for channel '{}'",
189-
&cs[0].description(manifest),
190-
toolchain,
191-
);
192-
if toolchain.starts_with("nightly") {
193-
let _ = write!(
151+
match cs {
152+
[] => panic!("`component_unavailable_msg` should not be called with an empty collection of unavailable components"),
153+
[c] => {
154+
_ = writeln!(
194155
buf,
195-
"Sometimes not all components are available in any given nightly. "
156+
"component {} is unavailable for download for channel '{}'",
157+
c.description(manifest),
158+
toolchain,
196159
);
160+
161+
if toolchain.starts_with("nightly") {
162+
_ = write!(
163+
buf,
164+
"Sometimes not all components are available in any given nightly. "
165+
);
166+
}
197167
}
198-
let _ = write!(
199-
buf,
200-
"If you don't need the component, you can remove it with:\n\n{}",
201-
remove_component_msg(&cs[0], manifest, toolchain)
202-
);
203-
} else {
204-
// More than one component
168+
cs => {
169+
// More than one component
170+
let same_target = cs
171+
.iter()
172+
.all(|c| c.target == cs[0].target || c.target.is_none());
205173

206-
let same_target = cs
207-
.iter()
208-
.all(|c| c.target == cs[0].target || c.target.is_none());
174+
let cs_str = if same_target {
175+
cs.iter()
176+
.map(|c| format!("'{}'", c.short_name(manifest)))
177+
.collect::<Vec<_>>()
178+
.join(", ")
179+
} else {
180+
cs.iter()
181+
.map(|c| c.description(manifest))
182+
.collect::<Vec<_>>()
183+
.join(", ")
184+
};
209185

210-
let cs_str = if same_target {
211-
cs.iter()
212-
.map(|c| format!("'{}'", c.short_name(manifest)))
213-
.collect::<Vec<_>>()
214-
.join(", ")
215-
} else {
216-
cs.iter()
217-
.map(|c| c.description(manifest))
218-
.collect::<Vec<_>>()
219-
.join(", ")
220-
};
186+
_ = write!(
187+
buf,
188+
"some components unavailable for download for channel '{toolchain}': {cs_str}"
189+
);
221190

222-
let remove_msg = cs
223-
.iter()
224-
.map(|c| remove_component_msg(c, manifest, toolchain))
225-
.collect::<Vec<_>>()
226-
.join("\n");
227-
let _ = write!(
228-
buf,
229-
"some components unavailable for download for channel '{toolchain}': {cs_str}\n\
230-
If you don't need the components, you can remove them with:\n\n{remove_msg}\n\n{TOOLSTATE_MSG}",
231-
);
191+
if toolchain.starts_with("nightly") {
192+
_ = write!(
193+
buf,
194+
"Sometimes not all components are available in any given nightly. "
195+
);
196+
}
197+
}
232198
}
233199

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

0 commit comments

Comments
 (0)