Skip to content

Commit 61fe20f

Browse files
committed
refactor(dist): inline some const strings in components_missing_msg()
1 parent fdc9f47 commit 61fe20f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/dist/mod.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";
4444
// Deprecated
4545
pub(crate) static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";
4646

47-
const TOOLSTATE_MSG: &str =
48-
"If you require the component(s), please install and use the latest successful build version,\n\
49-
which you can find at <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
50-
the correct date, install it with a command such as:\n\n \
51-
rustup toolchain install nightly-2018-12-27\n\n\
52-
Then you can use the toolchain with commands such as:\n\n \
53-
cargo +nightly-2018-12-27 build";
54-
5547
/// Returns a error message indicating that certain [`Component`]s are missing in a toolchain distribution.
5648
///
5749
/// This message is currently used exclusively in toolchain-wide operations,
@@ -61,8 +53,6 @@ const TOOLSTATE_MSG: &str =
6153
/// This function will panic when the collection of unavailable components `cs` is empty.
6254
fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &str) -> String {
6355
let mut buf = vec![];
64-
let suggestion = format!(" rustup toolchain add {toolchain} --profile minimal");
65-
let nightly_tips = "Sometimes not all components are available in any given nightly. ";
6656

6757
match cs {
6858
[] => panic!("`components_missing_msg` should not be called with an empty collection of unavailable components"),
@@ -88,13 +78,27 @@ fn components_missing_msg(cs: &[Component], manifest: &ManifestV2, toolchain: &s
8878
}
8979

9080
if toolchain.starts_with("nightly") {
91-
let _ = write!(buf, "{nightly_tips}");
92-
9381
let _ = write!(
9482
buf,
95-
"If you don't need the component(s), you could try a minimal installation with:\n\n{suggestion}\n\n{TOOLSTATE_MSG}"
83+
"\
84+
Sometimes not all components are available in any given nightly.
85+
If you don't need the component(s), you could try a minimal installation with:
86+
87+
rustup toolchain add {toolchain} --profile minimal
88+
89+
If you require the component(s), please install and use the latest successful build version,
90+
which you can find at <https://rust-lang.github.io/rustup-components-history>.
91+
92+
After determining the correct date, install it with a command such as:
93+
94+
rustup toolchain install nightly-2018-12-27
95+
96+
Then you can use the toolchain with commands such as:
97+
98+
cargo +nightly-2018-12-27 build"
9699
);
97-
}
100+
}
101+
98102
String::from_utf8(buf).unwrap()
99103
}
100104

tests/suite/cli_v2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,12 @@ async fn add_missing_component_toolchain() {
13431343
&["rustup", "toolchain", "add", "nightly"],
13441344
for_host!(
13451345
r"component 'rust-std' for target '{0}' is unavailable for download for channel 'nightly'
1346-
Sometimes not all components are available in any given nightly. If you don't need the component, you could try a minimal installation with:
1346+
Sometimes not all components are available in any given nightly.
1347+
If you don't need the component(s), you could try a minimal installation with:
13471348
13481349
rustup toolchain add nightly --profile minimal
13491350
1350-
If you require these components, please install and use the latest successful build version,
1351+
If you require the component(s), please install and use the latest successful build version,
13511352
which you can find at <https://rust-lang.github.io/rustup-components-history>.
13521353
13531354
After determining the correct date, install it with a command such as:

0 commit comments

Comments
 (0)