@@ -42,46 +42,57 @@ static TOOLCHAIN_CHANNELS: &[&str] = &[
4242 r"\d{1}\.\d{1,3}(?:\.\d{1,2})?" ,
4343] ;
4444
45+ /// Returns a error message indicating that certain [`Component`]s are missing in a toolchain distribution.
46+ ///
47+ /// This message is currently used exclusively in toolchain-wide operations,
48+ /// otherwise [`component_unavailable_msg`](../../errors/fn.component_unavailable_msg.html) will be used.
49+ ///
50+ /// # Panics
51+ /// This function will panic when the collection of unavailable components `cs` is empty.
4552fn components_missing_msg ( cs : & [ Component ] , manifest : & ManifestV2 , toolchain : & str ) -> String {
46- assert ! ( !cs. is_empty( ) ) ;
4753 let mut buf = vec ! [ ] ;
4854 let suggestion = format ! ( " rustup toolchain add {toolchain} --profile minimal" ) ;
4955 let nightly_tips = "Sometimes not all components are available in any given nightly. " ;
5056
51- if cs. len ( ) == 1 {
52- let _ = writeln ! (
53- buf,
54- "component {} is unavailable for download for channel '{}'" ,
55- & cs[ 0 ] . description( manifest) ,
56- toolchain,
57- ) ;
57+ match cs {
58+ [ ] => panic ! ( "`components_missing_msg` should not be called with an empty collection of unavailable components" ) ,
59+ [ c] => {
60+ _ = writeln ! (
61+ buf,
62+ "component {} is unavailable for download for channel '{}'" ,
63+ c. description( manifest) ,
64+ toolchain,
65+ ) ;
66+
67+ if toolchain. starts_with ( "nightly" ) {
68+ _ = write ! ( buf, "{nightly_tips}" ) ;
69+ }
5870
59- if toolchain. starts_with ( "nightly" ) {
60- let _ = write ! ( buf, "{nightly_tips}" ) ;
71+ _ = write ! (
72+ buf,
73+ "If you don't need the component, you could try a minimal installation with:\n \n {suggestion}"
74+ ) ;
6175 }
76+ cs => {
77+ let cs_str = cs
78+ . iter ( )
79+ . map ( |c| c. description ( manifest) )
80+ . collect :: < Vec < _ > > ( )
81+ . join ( ", " ) ;
82+ _ = write ! (
83+ buf,
84+ "some components unavailable for download for channel '{toolchain}': {cs_str}"
85+ ) ;
6286
63- let _ = write ! (
64- buf,
65- "If you don't need the component, you could try a minimal installation with:\n \n {suggestion}"
66- ) ;
67- } else {
68- let cs_str = cs
69- . iter ( )
70- . map ( |c| c. description ( manifest) )
71- . collect :: < Vec < _ > > ( )
72- . join ( ", " ) ;
73- let _ = write ! (
74- buf,
75- "some components unavailable for download for channel '{toolchain}': {cs_str}"
76- ) ;
87+ if toolchain. starts_with ( "nightly" ) {
88+ let _ = write ! ( buf, "{nightly_tips}" ) ;
89+ }
7790
78- if toolchain. starts_with ( "nightly" ) {
79- let _ = write ! ( buf, "{nightly_tips}" ) ;
91+ _ = write ! (
92+ buf,
93+ "If you don't need the components, you could try a minimal installation with:\n \n {suggestion}"
94+ ) ;
8095 }
81- let _ = write ! (
82- buf,
83- "If you don't need the components, you could try a minimal installation with:\n \n {suggestion}"
84- ) ;
8596 }
8697
8798 String :: from_utf8 ( buf) . unwrap ( )
0 commit comments