Skip to content

Commit 7223c50

Browse files
committed
Rename ActiveReason to ActiveSource
1 parent 30ee45b commit 7223c50

File tree

4 files changed

+59
-59
lines changed

4 files changed

+59
-59
lines changed

src/cli/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub(crate) async fn list_toolchains(
332332
} else {
333333
let default_toolchain_name = cfg.get_default()?;
334334
let active_toolchain_name: Option<ToolchainName> =
335-
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
335+
if let Ok(Some((LocalToolchainName::Named(toolchain), _source))) =
336336
cfg.maybe_ensure_active_toolchain(None).await
337337
{
338338
Some(toolchain)

src/cli/rustup_mode.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
topical_doc,
3232
},
3333
command, component_for_bin,
34-
config::{ActiveReason, Cfg},
34+
config::{ActiveSource, Cfg},
3535
dist::{
3636
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
3737
manifest::{Component, ComponentStatus},
@@ -779,10 +779,10 @@ async fn default_(
779779
}
780780
};
781781

782-
if let Some((toolchain, reason)) = cfg.active_toolchain()?
783-
&& !matches!(reason, ActiveReason::Default)
782+
if let Some((toolchain, source)) = cfg.active_toolchain()?
783+
&& !matches!(source, ActiveSource::Default)
784784
{
785-
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
785+
info!("note that the toolchain '{toolchain}' is currently in use ({source})");
786786
}
787787
} else {
788788
let default_toolchain = cfg
@@ -997,9 +997,9 @@ async fn update(
997997
exit_code &= self_update::self_update(cfg.process).await?;
998998
}
999999
} else if ensure_active_toolchain {
1000-
let (toolchain, reason) = cfg.ensure_active_toolchain(force_non_host, true).await?;
1000+
let (toolchain, source) = cfg.ensure_active_toolchain(force_non_host, true).await?;
10011001
info!("the active toolchain `{toolchain}` has been installed");
1002-
info!("it's active because: {reason}");
1002+
info!("it's active because: {source}");
10031003
} else {
10041004
exit_code &= common::update_all_channels(cfg, opts.force).await?;
10051005
if self_update {
@@ -1088,16 +1088,16 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
10881088
}
10891089

10901090
let installed_toolchains = cfg.list_toolchains()?;
1091-
let active_toolchain_and_reason: Option<(ToolchainName, ActiveReason)> =
1092-
if let Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) =
1091+
let active_toolchain_and_source: Option<(ToolchainName, ActiveSource)> =
1092+
if let Ok(Some((LocalToolchainName::Named(toolchain_name), source))) =
10931093
cfg.maybe_ensure_active_toolchain(None).await
10941094
{
1095-
Some((toolchain_name, reason))
1095+
Some((toolchain_name, source))
10961096
} else {
10971097
None
10981098
};
10991099

1100-
let (active_toolchain_name, _active_reason) = active_toolchain_and_reason
1100+
let (active_toolchain_name, _active_source) = active_toolchain_and_source
11011101
.as_ref()
11021102
.map(|atar| (&atar.0, &atar.1))
11031103
.unzip();
@@ -1161,15 +1161,15 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
11611161

11621162
print_header(&mut t, "active toolchain")?;
11631163

1164-
match active_toolchain_and_reason {
1165-
Some((active_toolchain_name, active_reason)) => {
1166-
let active_toolchain = Toolchain::with_reason(
1164+
match active_toolchain_and_source {
1165+
Some((active_toolchain_name, active_source)) => {
1166+
let active_toolchain = Toolchain::with_source(
11671167
cfg,
11681168
active_toolchain_name.clone().into(),
1169-
&active_reason,
1169+
&active_source,
11701170
)?;
11711171
writeln!(t.lock(), "name: {}", active_toolchain.name())?;
1172-
writeln!(t.lock(), "active because: {active_reason}")?;
1172+
writeln!(t.lock(), "active because: {active_source}")?;
11731173
if verbose {
11741174
writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?;
11751175
writeln!(t.lock(), "path: {}", active_toolchain.path().display())?;
@@ -1205,14 +1205,14 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
12051205
#[tracing::instrument(level = "trace", skip_all)]
12061206
async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
12071207
match cfg.maybe_ensure_active_toolchain(None).await? {
1208-
Some((toolchain_name, reason)) => {
1209-
let toolchain = Toolchain::with_reason(cfg, toolchain_name.clone(), &reason)?;
1208+
Some((toolchain_name, source)) => {
1209+
let toolchain = Toolchain::with_source(cfg, toolchain_name.clone(), &source)?;
12101210
if verbose {
12111211
writeln!(
12121212
cfg.process.stdout().lock(),
12131213
"{}\nactive because: {}\ncompiler: {}\npath: {}",
12141214
toolchain.name(),
1215-
reason,
1215+
source,
12161216
toolchain.rustc_version(),
12171217
toolchain.path().display()
12181218
)?;
@@ -1221,9 +1221,9 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12211221
cfg.process.stdout().lock(),
12221222
"{} ({})",
12231223
toolchain.name(),
1224-
match reason {
1225-
ActiveReason::Default => &"default" as &dyn fmt::Display,
1226-
_ => &reason,
1224+
match source {
1225+
ActiveSource::Default => &"default" as &dyn fmt::Display,
1226+
_ => &source,
12271227
}
12281228
)?;
12291229
}

src/config.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ impl<T: Into<String>> From<T> for OverrideFile {
9292
}
9393
}
9494

95-
// Represents the reason why the active toolchain is active.
95+
// Represents the source that determined the current active toolchain.
9696
#[derive(Debug)]
97-
pub(crate) enum ActiveReason {
97+
pub(crate) enum ActiveSource {
9898
Default,
9999
Environment,
100100
CommandLine,
101101
OverrideDB(PathBuf),
102102
ToolchainFile(PathBuf),
103103
}
104104

105-
impl Display for ActiveReason {
105+
impl Display for ActiveSource {
106106
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
107107
match self {
108108
Self::Default => write!(f, "it's the default toolchain"),
@@ -505,7 +505,7 @@ impl<'a> Cfg<'a> {
505505
pub(crate) async fn maybe_ensure_active_toolchain(
506506
&self,
507507
force_ensure: Option<bool>,
508-
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
508+
) -> Result<Option<(LocalToolchainName, ActiveSource)>> {
509509
let should_ensure = if let Some(force) = force_ensure {
510510
force
511511
} else {
@@ -524,39 +524,39 @@ impl<'a> Cfg<'a> {
524524
}
525525
}
526526

527-
pub(crate) fn active_toolchain(&self) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
527+
pub(crate) fn active_toolchain(&self) -> Result<Option<(LocalToolchainName, ActiveSource)>> {
528528
Ok(
529-
if let Some((override_config, reason)) = self.find_override_config()? {
530-
Some((override_config.into_local_toolchain_name(), reason))
529+
if let Some((override_config, source)) = self.find_override_config()? {
530+
Some((override_config.into_local_toolchain_name(), source))
531531
} else {
532532
self.get_default()?
533-
.map(|x| (x.into(), ActiveReason::Default))
533+
.map(|x| (x.into(), ActiveSource::Default))
534534
},
535535
)
536536
}
537537

538-
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveReason)>> {
539-
let override_config: Option<(OverrideCfg, ActiveReason)> =
538+
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveSource)>> {
539+
let override_config: Option<(OverrideCfg, ActiveSource)> =
540540
// First check +toolchain override from the command line
541541
if let Some(name) = &self.toolchain_override {
542542
let override_config = name.resolve(&self.get_default_host_triple()?)?.into();
543-
Some((override_config, ActiveReason::CommandLine))
543+
Some((override_config, ActiveSource::CommandLine))
544544
}
545545
// Then check the RUSTUP_TOOLCHAIN environment variable
546546
else if let Some(name) = &self.env_override {
547547
// Because path based toolchain files exist, this has to support
548548
// custom, distributable, and absolute path toolchains otherwise
549549
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
550550
// error when a nested rustup invocation occurs
551-
Some((name.clone().into(), ActiveReason::Environment))
551+
Some((name.clone().into(), ActiveSource::Environment))
552552
}
553553
// Then walk up the directory tree from 'path' looking for either the
554554
// directory in the override database, or a `rust-toolchain{.toml}` file,
555555
// in that order.
556-
else if let Some((override_cfg, active_reason)) = self.settings_file.with(|s| {
556+
else if let Some((override_cfg, active_source)) = self.settings_file.with(|s| {
557557
self.find_override_from_dir_walk(&self.current_dir, s)
558558
})? {
559-
Some((override_cfg, active_reason))
559+
Some((override_cfg, active_source))
560560
}
561561
// Otherwise, there is no override.
562562
else {
@@ -570,13 +570,13 @@ impl<'a> Cfg<'a> {
570570
&self,
571571
dir: &Path,
572572
settings: &Settings,
573-
) -> Result<Option<(OverrideCfg, ActiveReason)>> {
573+
) -> Result<Option<(OverrideCfg, ActiveSource)>> {
574574
let mut dir = Some(dir);
575575

576576
while let Some(d) = dir {
577577
// First check the override database
578578
if let Some(name) = settings.dir_override(d) {
579-
let reason = ActiveReason::OverrideDB(d.to_owned());
579+
let source = ActiveSource::OverrideDB(d.to_owned());
580580
// Note that `rustup override set` fully resolves it's input
581581
// before writing to settings.toml, so resolving here may not
582582
// be strictly necessary (could instead model as ToolchainName).
@@ -586,7 +586,7 @@ impl<'a> Cfg<'a> {
586586
let toolchain_name = ResolvableToolchainName::try_from(name)?
587587
.resolve(&get_default_host_triple(settings, self.process))?;
588588
let override_cfg = toolchain_name.into();
589-
return Ok(Some((override_cfg, reason)));
589+
return Ok(Some((override_cfg, source)));
590590
}
591591

592592
// Then look for 'rust-toolchain' or 'rust-toolchain.toml'
@@ -670,9 +670,9 @@ impl<'a> Cfg<'a> {
670670
}
671671
}
672672

673-
let reason = ActiveReason::ToolchainFile(toolchain_file);
673+
let source = ActiveSource::ToolchainFile(toolchain_file);
674674
let override_cfg = OverrideCfg::from_file(self, override_file)?;
675-
return Ok(Some((override_cfg, reason)));
675+
return Ok(Some((override_cfg, source)));
676676
}
677677

678678
dir = d.parent();
@@ -766,8 +766,8 @@ impl<'a> Cfg<'a> {
766766
&self,
767767
force_non_host: bool,
768768
verbose: bool,
769-
) -> Result<(LocalToolchainName, ActiveReason)> {
770-
if let Some((override_config, reason)) = self.find_override_config()? {
769+
) -> Result<(LocalToolchainName, ActiveSource)> {
770+
if let Some((override_config, source)) = self.find_override_config()? {
771771
let toolchain = override_config.clone().into_local_toolchain_name();
772772
if let OverrideCfg::Official {
773773
toolchain,
@@ -786,18 +786,18 @@ impl<'a> Cfg<'a> {
786786
)
787787
.await?;
788788
} else {
789-
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
789+
Toolchain::with_source(self, toolchain.clone(), &source)?;
790790
}
791-
Ok((toolchain, reason))
791+
Ok((toolchain, source))
792792
} else if let Some(toolchain) = self.get_default()? {
793-
let reason = ActiveReason::Default;
793+
let source = ActiveSource::Default;
794794
if let ToolchainName::Official(desc) = &toolchain {
795795
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
796796
.await?;
797797
} else {
798-
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
798+
Toolchain::with_source(self, toolchain.clone().into(), &source)?;
799799
}
800-
Ok((toolchain.into(), reason))
800+
Ok((toolchain.into(), source))
801801
} else {
802802
Err(no_toolchain_error(self.process))
803803
}

src/toolchain.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use wait_timeout::ChildExt;
2121

2222
use crate::{
2323
RustupError,
24-
config::{ActiveReason, Cfg, InstalledPath},
24+
config::{ActiveSource, Cfg, InstalledPath},
2525
dist::{
2626
PartialToolchainDesc, TargetTriple,
2727
component::{Component, Components},
@@ -73,11 +73,11 @@ impl<'a> Toolchain<'a> {
7373
}
7474

7575
/// Calls Toolchain::new(), but augments the error message with more context
76-
/// from the ActiveReason if the toolchain isn't installed.
77-
pub(crate) fn with_reason(
76+
/// from the ActiveSource if the toolchain isn't installed.
77+
pub(crate) fn with_source(
7878
cfg: &'a Cfg<'a>,
7979
name: LocalToolchainName,
80-
reason: &ActiveReason,
80+
source: &ActiveSource,
8181
) -> anyhow::Result<Self> {
8282
match Self::new(cfg, name.clone()) {
8383
Err(RustupError::ToolchainNotInstalled { .. }) => (),
@@ -86,28 +86,28 @@ impl<'a> Toolchain<'a> {
8686
}
8787
}
8888

89-
let reason_err = match reason {
90-
ActiveReason::Environment => {
89+
let source_err = match source {
90+
ActiveSource::Environment => {
9191
"the RUSTUP_TOOLCHAIN environment variable specifies an uninstalled toolchain"
9292
.to_string()
9393
}
94-
ActiveReason::CommandLine => {
94+
ActiveSource::CommandLine => {
9595
"the +toolchain on the command line specifies an uninstalled toolchain".to_string()
9696
}
97-
ActiveReason::OverrideDB(path) => format!(
97+
ActiveSource::OverrideDB(path) => format!(
9898
"the directory override for '{}' specifies an uninstalled toolchain",
9999
utils::canonicalize_path(path).display(),
100100
),
101-
ActiveReason::ToolchainFile(path) => format!(
101+
ActiveSource::ToolchainFile(path) => format!(
102102
"the toolchain file at '{}' specifies an uninstalled toolchain",
103103
utils::canonicalize_path(path).display(),
104104
),
105-
ActiveReason::Default => {
105+
ActiveSource::Default => {
106106
"the default toolchain does not describe an installed toolchain".to_string()
107107
}
108108
};
109109

110-
Err(anyhow!(reason_err).context(format!("override toolchain '{name}' is not installed")))
110+
Err(anyhow!(source_err).context(format!("override toolchain '{name}' is not installed")))
111111
}
112112

113113
pub(crate) fn new(cfg: &'a Cfg<'a>, name: LocalToolchainName) -> Result<Self, RustupError> {

0 commit comments

Comments
 (0)