Skip to content

Commit 989650a

Browse files
committed
Move Display impl to to_reason()
1 parent 7223c50 commit 989650a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/cli/rustup_mode.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,10 @@ async fn default_(
782782
if let Some((toolchain, source)) = cfg.active_toolchain()?
783783
&& !matches!(source, ActiveSource::Default)
784784
{
785-
info!("note that the toolchain '{toolchain}' is currently in use ({source})");
785+
info!(
786+
"note that the toolchain '{toolchain}' is currently in use ({})",
787+
source.to_reason()
788+
);
786789
}
787790
} else {
788791
let default_toolchain = cfg
@@ -999,7 +1002,7 @@ async fn update(
9991002
} else if ensure_active_toolchain {
10001003
let (toolchain, source) = cfg.ensure_active_toolchain(force_non_host, true).await?;
10011004
info!("the active toolchain `{toolchain}` has been installed");
1002-
info!("it's active because: {source}");
1005+
info!("it's active because: {}", source.to_reason());
10031006
} else {
10041007
exit_code &= common::update_all_channels(cfg, opts.force).await?;
10051008
if self_update {
@@ -1169,7 +1172,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
11691172
&active_source,
11701173
)?;
11711174
writeln!(t.lock(), "name: {}", active_toolchain.name())?;
1172-
writeln!(t.lock(), "active because: {active_source}")?;
1175+
writeln!(t.lock(), "active because: {}", active_source.to_reason())?;
11731176
if verbose {
11741177
writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?;
11751178
writeln!(t.lock(), "path: {}", active_toolchain.path().display())?;
@@ -1212,7 +1215,7 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12121215
cfg.process.stdout().lock(),
12131216
"{}\nactive because: {}\ncompiler: {}\npath: {}",
12141217
toolchain.name(),
1215-
source,
1218+
source.to_reason(),
12161219
toolchain.rustc_version(),
12171220
toolchain.path().display()
12181221
)?;
@@ -1223,7 +1226,7 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12231226
toolchain.name(),
12241227
match source {
12251228
ActiveSource::Default => &"default" as &dyn fmt::Display,
1226-
_ => &source,
1229+
_ => &source.to_reason(),
12271230
}
12281231
)?;
12291232
}

src/config.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{self, Debug, Display};
1+
use std::fmt::{self, Debug};
22
use std::io;
33
use std::path::{Path, PathBuf};
44
use std::str::FromStr;
@@ -102,14 +102,16 @@ pub(crate) enum ActiveSource {
102102
ToolchainFile(PathBuf),
103103
}
104104

105-
impl Display for ActiveSource {
106-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
105+
impl ActiveSource {
106+
pub fn to_reason(&self) -> String {
107107
match self {
108-
Self::Default => write!(f, "it's the default toolchain"),
109-
Self::Environment => write!(f, "overridden by environment variable RUSTUP_TOOLCHAIN"),
110-
Self::CommandLine => write!(f, "overridden by +toolchain on the command line"),
111-
Self::OverrideDB(path) => write!(f, "directory override for '{}'", path.display()),
112-
Self::ToolchainFile(path) => write!(f, "overridden by '{}'", path.display()),
108+
Self::Default => String::from("it's the default toolchain"),
109+
Self::Environment => {
110+
String::from("overridden by environment variable RUSTUP_TOOLCHAIN")
111+
}
112+
Self::CommandLine => String::from("overridden by +toolchain on the command line"),
113+
Self::OverrideDB(path) => format!("directory override for '{}'", path.display()),
114+
Self::ToolchainFile(path) => format!("overridden by '{}'", path.display()),
113115
}
114116
}
115117
}

0 commit comments

Comments
 (0)