diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 0e834d627a..1d5ec2b89e 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -369,6 +369,7 @@ fn do_pre_install_sanity_checks() -> Result<()> { // If the user is trying to install with sudo, on some systems this will // result in writing root-owned files to the user's home directory, because // sudo is configured not to change $HOME. Don't let that bogosity happen. +#[allow(dead_code)] fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { #[cfg(unix)] #[inline(never)] // FIXME #679. Mysterious crashes on OS X 10.10+ diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index d862b390c7..9d351a54e6 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -20,6 +20,7 @@ use std::env; use url::Url; +/// A fully resolved reference to a toolchain which may or may not exist pub struct Toolchain<'a> { cfg: &'a Cfg, name: String, @@ -276,8 +277,14 @@ impl<'a> Toolchain<'a> { return Err(ErrorKind::ToolchainNotInstalled(self.name.to_owned()).into()); } - let bin_path = &self.path.join("bin").join(binary.as_ref()); - let mut cmd = Command::new(bin_path); + // Assume this binary exists within the current toolchain + let bin_path = self.path.join("bin").join(binary.as_ref()); + let mut cmd = Command::new(if utils::is_file(&bin_path) { + &bin_path + } else { + // If not, let the OS try to resolve it globally for us + Path::new(&binary) + }); self.set_env(&mut cmd); Ok(cmd) } diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index ce536f4f9f..0584420493 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -283,6 +283,19 @@ fn custom_toolchain_cargo_fallback_run() { }); } +#[test] +fn rustup_run_searches_path() { + setup(&|config| { + #[cfg(windows)] + let hello_cmd = &["rustup", "run", "nightly", "cmd", "/C", "echo hello"]; + #[cfg(not(windows))] + let hello_cmd = &["rustup", "run", "nightly", "sh", "-c", "echo hello"]; + + expect_ok(config, &["rustup", "default", "nightly"]); + expect_stdout_ok(config, hello_cmd, "hello"); + }); +} + #[test] fn multirust_env_compat() { setup(&|config| {