Skip to content

Commit 64f2624

Browse files
smoeliusdjc
authored andcommitted
Move Display impl to to_reason()
1 parent 2705e87 commit 64f2624

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
@@ -784,7 +784,10 @@ async fn default_(
784784
if let Some((toolchain, source)) = cfg.active_toolchain()?
785785
&& !matches!(source, ActiveSource::Default)
786786
{
787-
info!("note that the toolchain '{toolchain}' is currently in use ({source})");
787+
info!(
788+
"note that the toolchain '{toolchain}' is currently in use ({})",
789+
source.to_reason()
790+
);
788791
}
789792
} else {
790793
let default_toolchain = cfg
@@ -1004,7 +1007,7 @@ async fn update(
10041007
} else if ensure_active_toolchain {
10051008
let (toolchain, source) = cfg.ensure_active_toolchain(force_non_host, true).await?;
10061009
info!("the active toolchain `{toolchain}` has been installed");
1007-
info!("it's active because: {source}");
1010+
info!("it's active because: {}", source.to_reason());
10081011
} else {
10091012
exit_code &= common::update_all_channels(cfg, opts.force).await?;
10101013
if self_update {
@@ -1180,7 +1183,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
11801183
&active_source,
11811184
)?;
11821185
writeln!(t.lock(), "name: {}", active_toolchain.name())?;
1183-
writeln!(t.lock(), "active because: {active_source}")?;
1186+
writeln!(t.lock(), "active because: {}", active_source.to_reason())?;
11841187
if verbose {
11851188
writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?;
11861189
writeln!(t.lock(), "path: {}", active_toolchain.path().display())?;
@@ -1221,7 +1224,7 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12211224
cfg.process.stdout().lock(),
12221225
"{}\nactive because: {}\ncompiler: {}\npath: {}",
12231226
toolchain.name(),
1224-
source,
1227+
source.to_reason(),
12251228
toolchain.rustc_version(),
12261229
toolchain.path().display()
12271230
)?;
@@ -1232,7 +1235,7 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12321235
toolchain.name(),
12331236
match source {
12341237
ActiveSource::Default => &"default" as &dyn fmt::Display,
1235-
_ => &source,
1238+
_ => &source.to_reason(),
12361239
}
12371240
)?;
12381241
}

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;
@@ -97,14 +97,16 @@ pub(crate) enum ActiveSource {
9797
ToolchainFile(PathBuf),
9898
}
9999

100-
impl Display for ActiveSource {
101-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
100+
impl ActiveSource {
101+
pub fn to_reason(&self) -> String {
102102
match self {
103-
Self::Default => write!(f, "it's the default toolchain"),
104-
Self::Environment => write!(f, "overridden by environment variable RUSTUP_TOOLCHAIN"),
105-
Self::CommandLine => write!(f, "overridden by +toolchain on the command line"),
106-
Self::OverrideDB(path) => write!(f, "directory override for '{}'", path.display()),
107-
Self::ToolchainFile(path) => write!(f, "overridden by '{}'", path.display()),
103+
Self::Default => String::from("it's the default toolchain"),
104+
Self::Environment => {
105+
String::from("overridden by environment variable RUSTUP_TOOLCHAIN")
106+
}
107+
Self::CommandLine => String::from("overridden by +toolchain on the command line"),
108+
Self::OverrideDB(path) => format!("directory override for '{}'", path.display()),
109+
Self::ToolchainFile(path) => format!("overridden by '{}'", path.display()),
108110
}
109111
}
110112
}

0 commit comments

Comments
 (0)