Skip to content
11 changes: 2 additions & 9 deletions doc/user-guide/src/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ the directory tree toward the filesystem root, and a `rust-toolchain.toml` file
that is closer to the current directory will be preferred over a directory
override that is further away.

To verify which toolchain is active, you can use `rustup show`,
which will also try to install the corresponding
toolchain if the current one has not been installed according to the above rules.
(Please note that this behavior is subject to change, as detailed in issue [#1397].)
To verify which toolchain is active, you can use `rustup show`.

[toolchain]: concepts/toolchains.md
[toolchain override shorthand]: #toolchain-override-shorthand
Expand Down Expand Up @@ -123,16 +120,12 @@ The `channel` setting specifies which [toolchain] to use. The value is a
string in the following form:

```
<channel>[-<date>]
(<channel>[-<date>])|<custom toolchain name>

<channel> = stable|beta|nightly|<major.minor.patch>
<date> = YYYY-MM-DD
```

Note that this is a more restricted form than `rustup` toolchains
generally, and cannot be used to specify custom toolchains or
host-specific toolchains.

[toolchain]: concepts/toolchains.md

#### path
Expand Down
105 changes: 52 additions & 53 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::currentprocess::{
use crate::dist::dist::{TargetTriple, ToolchainDesc};
use crate::dist::manifest::ComponentStatus;
use crate::install::UpdateStatus;
use crate::toolchain::names::{LocalToolchainName, ToolchainName};
use crate::utils::notifications as util_notifications;
use crate::utils::notify::NotificationLevel;
use crate::utils::utils;
Expand Down Expand Up @@ -425,74 +426,72 @@ fn list_items(
Ok(utils::ExitCode(0))
}

fn print_toolchain_path(
cfg: &Cfg,
toolchain: &str,
if_default: &str,
if_override: &str,
verbose: bool,
) -> Result<()> {
let toolchain_path = cfg.toolchains_dir.join(toolchain);
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
let toolchain_path = if verbose {
if toolchain_meta.is_dir() {
format!("\t{}", toolchain_path.display())
} else {
format!("\t{}", fs::read_link(toolchain_path)?.display())
}
} else {
String::new()
};
writeln!(
process().stdout().lock(),
"{}{}{}{}",
&toolchain,
if_default,
if_override,
toolchain_path
)?;
Ok(())
}

pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
// Work with LocalToolchainName to accommodate path based overrides
let toolchains = cfg
.list_toolchains()?
.iter()
.map(Into::into)
.collect::<Vec<_>>();
let toolchains = cfg.list_toolchains()?;
if toolchains.is_empty() {
writeln!(process().stdout().lock(), "no installed toolchains")?;
} else {
let def_toolchain_name = cfg.get_default()?.map(|t| (&t).into());
let default_toolchain_name = cfg.get_default()?;
let cwd = utils::current_dir()?;
let ovr_toolchain_name = if let Ok(Some((toolchain, _reason))) = cfg.find_override(&cwd) {
Some(toolchain)
} else {
None
};
for toolchain in toolchains {
let if_default = if def_toolchain_name.as_ref() == Some(&toolchain) {
" (default)"
let active_toolchain_name: Option<ToolchainName> =
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
cfg.find_active_toolchain(&cwd)
{
Some(toolchain)
} else {
""
};
let if_override = if ovr_toolchain_name.as_ref() == Some(&toolchain) {
" (override)"
} else {
""
None
};

print_toolchain_path(
for toolchain in toolchains {
let is_default_toolchain = default_toolchain_name.as_ref() == Some(&toolchain);
let is_active_toolchain = active_toolchain_name.as_ref() == Some(&toolchain);

print_toolchain(
cfg,
&toolchain.to_string(),
if_default,
if_override,
is_default_toolchain,
is_active_toolchain,
verbose,
)
.context("Failed to list toolchains' directories")?;
}
}

fn print_toolchain(
cfg: &Cfg,
toolchain: &str,
is_default: bool,
is_active: bool,
verbose: bool,
) -> Result<()> {
let toolchain_path = cfg.toolchains_dir.join(toolchain);
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
let toolchain_path = if verbose {
if toolchain_meta.is_dir() {
format!(" {}", toolchain_path.display())
} else {
format!(" {}", fs::read_link(toolchain_path)?.display())
}
} else {
String::new()
};
let status_str = match (is_default, is_active) {
(true, true) => " (active, default)",
(true, false) => " (default)",
(false, true) => " (active)",
(false, false) => "",
};

writeln!(
process().stdout().lock(),
"{}{}{}",
&toolchain,
status_str,
toolchain_path
)?;
Ok(())
}

Ok(utils::ExitCode(0))
}

Expand Down
Loading