diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 59996f7221..a3df07292f 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -512,6 +512,7 @@ pub(crate) async fn install( .map_or(false, |s| s == "yes") { check_existence_of_rustc_or_cargo_in_path(no_prompt, process)?; + check_existence_of_settings_file(process)?; } #[cfg(unix)] @@ -631,7 +632,7 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool, process: &Process) } if let Err(path) = rustc_or_cargo_exists_in_path(process) { - warn!("it looks like you have an existing installation of Rust at:"); + warn!("It looks like you have an existing installation of Rust at:"); warn!("{}", path); warn!("It is recommended that rustup be the primary Rust installation."); warn!("Otherwise you may have confusion unless you are careful with your PATH."); @@ -643,6 +644,18 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool, process: &Process) Ok(()) } +fn check_existence_of_settings_file(process: &Process) -> Result<()> { + let rustup_dir = process.rustup_home()?; + let settings_file_path = rustup_dir.join("settings.toml"); + if utils::path_exists(&settings_file_path) { + warn!("It looks like you have an existing rustup settings file at:"); + warn!("{}", settings_file_path.display()); + warn!("Rustup will install the default toolchain as specified in the settings file,"); + warn!("instead of the one inferred from the default host triple."); + } + Ok(()) +} + fn pre_install_msg(no_modify_path: bool, process: &Process) -> Result { let cargo_home = process.cargo_home()?; let cargo_home_bin = cargo_home.join("bin"); diff --git a/tests/suite/cli_inst_interactive.rs b/tests/suite/cli_inst_interactive.rs index ad15fe605e..adbd52bd04 100644 --- a/tests/suite/cli_inst_interactive.rs +++ b/tests/suite/cli_inst_interactive.rs @@ -498,7 +498,7 @@ async fn install_stops_if_rustc_exists() { assert!(!out.ok); assert!(out .stderr - .contains("it looks like you have an existing installation of Rust at:")); + .contains("It looks like you have an existing installation of Rust at:")); assert!(out .stderr .contains("If you are sure that you want both rustup and your already installed Rust")); @@ -530,7 +530,7 @@ async fn install_stops_if_cargo_exists() { assert!(!out.ok); assert!(out .stderr - .contains("it looks like you have an existing installation of Rust at:")); + .contains("It looks like you have an existing installation of Rust at:")); assert!(out .stderr .contains("If you are sure that you want both rustup and your already installed Rust")); @@ -579,3 +579,40 @@ async fn install_non_installable_toolchain() { ) .await; } + +#[tokio::test] +async fn install_warns_about_existing_settings_file() { + let temp_dir = tempfile::Builder::new() + .prefix("fakehome") + .tempdir() + .unwrap(); + // Create `settings.toml` + let settings_file = temp_dir.path().join("settings.toml"); + raw::write_file( + &settings_file, + for_host!( + r#"default_toolchain = "{}" +profile = "default" +version = "12""# + ), + ) + .unwrap(); + let temp_dir_path = temp_dir.path().to_str().unwrap(); + + let cx = CliTestContext::new(Scenario::SimpleV2).await; + let out = cx + .config + .run( + "rustup-init", + ["-y", "--no-modify-path"], + &[ + ("RUSTUP_INIT_SKIP_PATH_CHECK", "no"), + ("RUSTUP_HOME", temp_dir_path), + ], + ) + .await; + assert!(out.ok); + assert!(out + .stderr + .contains("It looks like you have an existing rustup settings file at:")); +}