@@ -41,6 +41,7 @@ use rustup::utils::Notification;
41
41
use rustup:: { Cfg , UpdateStatus } ;
42
42
use rustup:: { DUP_TOOLS , TOOLS } ;
43
43
use same_file:: Handle ;
44
+ use std:: borrow:: Cow ;
44
45
use std:: env;
45
46
use std:: env:: consts:: EXE_SUFFIX ;
46
47
use std:: fs;
@@ -65,7 +66,7 @@ pub const NEVER_SELF_UPDATE: bool = false;
65
66
// argument of format! needs to be a literal.
66
67
67
68
macro_rules! pre_install_msg_template {
68
- ( $platform_msg: expr ) => {
69
+ ( $platform_msg: literal ) => {
69
70
concat!(
70
71
r"
71
72
# Welcome to Rust!
@@ -215,22 +216,21 @@ static UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
215
216
216
217
/// `CARGO_HOME` suitable for display, possibly with $HOME
217
218
/// substituted for the directory prefix
218
- fn canonical_cargo_home ( ) -> Result < String > {
219
+ fn canonical_cargo_home ( ) -> Result < Cow < ' static , str > > {
219
220
let path = utils:: cargo_home ( ) ?;
220
- let mut path_str = path. to_string_lossy ( ) . into_owned ( ) ;
221
221
222
222
let default_cargo_home = utils:: home_dir ( )
223
223
. unwrap_or_else ( || PathBuf :: from ( "." ) )
224
224
. join ( ".cargo" ) ;
225
- if default_cargo_home == path {
225
+ Ok ( if default_cargo_home == path {
226
226
if cfg ! ( unix) {
227
- path_str = String :: from ( "$HOME/.cargo" ) ;
227
+ "$HOME/.cargo" . into ( )
228
228
} else {
229
- path_str = String :: from ( r"%USERPROFILE%\.cargo" ) ;
229
+ r"%USERPROFILE%\.cargo" . into ( )
230
230
}
231
- }
232
-
233
- Ok ( path_str )
231
+ } else {
232
+ path . to_string_lossy ( ) . into_owned ( ) . into ( )
233
+ } )
234
234
}
235
235
236
236
/// Installing is a simple matter of copying the running binary to
@@ -327,22 +327,19 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
327
327
}
328
328
329
329
let cargo_home = canonical_cargo_home ( ) ?;
330
- let msg = if !opts. no_modify_path {
331
- if cfg ! ( unix) {
332
- format ! ( post_install_msg_unix!( ) , cargo_home = cargo_home)
333
- } else {
334
- format ! ( post_install_msg_win!( ) , cargo_home = cargo_home)
335
- }
336
- } else if cfg ! ( unix) {
337
- format ! (
330
+ #[ cfg( windows) ]
331
+ let cargo_home = cargo_home. replace ( '\\' , r"\\" ) ;
332
+ let msg = match ( opts. no_modify_path , cfg ! ( unix) ) {
333
+ ( false , true ) => format ! ( post_install_msg_unix!( ) , cargo_home = cargo_home) ,
334
+ ( false , false ) => format ! ( post_install_msg_win!( ) , cargo_home = cargo_home) ,
335
+ ( true , true ) => format ! (
338
336
post_install_msg_unix_no_modify_path!( ) ,
339
337
cargo_home = cargo_home
340
- )
341
- } else {
342
- format ! (
338
+ ) ,
339
+ ( true , false ) => format ! (
343
340
post_install_msg_win_no_modify_path!( ) ,
344
341
cargo_home = cargo_home
345
- )
342
+ ) ,
346
343
} ;
347
344
md ( & mut term, msg) ;
348
345
0 commit comments