Skip to content

Commit 2705e87

Browse files
smoeliusdjc
authored andcommitted
Rename ActiveReason to ActiveSource
1 parent c59cd9c commit 2705e87

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
@@ -279,7 +279,7 @@ pub(crate) async fn list_toolchains(
279279
} else {
280280
let default_toolchain_name = cfg.get_default()?;
281281
let active_toolchain_name: Option<ToolchainName> =
282-
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
282+
if let Ok(Some((LocalToolchainName::Named(toolchain), _source))) =
283283
cfg.maybe_ensure_active_toolchain(None).await
284284
{
285285
Some(toolchain)

src/cli/rustup_mode.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
topical_doc,
3333
},
3434
command, component_for_bin,
35-
config::{ActiveReason, Cfg},
35+
config::{ActiveSource, Cfg},
3636
dist::{
3737
AutoInstallMode, PartialToolchainDesc, Profile, TargetTriple,
3838
download::DownloadCfg,
@@ -781,10 +781,10 @@ async fn default_(
781781
}
782782
};
783783

784-
if let Some((toolchain, reason)) = cfg.active_toolchain()?
785-
&& !matches!(reason, ActiveReason::Default)
784+
if let Some((toolchain, source)) = cfg.active_toolchain()?
785+
&& !matches!(source, ActiveSource::Default)
786786
{
787-
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
787+
info!("note that the toolchain '{toolchain}' is currently in use ({source})");
788788
}
789789
} else {
790790
let default_toolchain = cfg
@@ -1002,9 +1002,9 @@ async fn update(
10021002
exit_code &= self_update::self_update(&dl_cfg).await?;
10031003
}
10041004
} else if ensure_active_toolchain {
1005-
let (toolchain, reason) = cfg.ensure_active_toolchain(force_non_host, true).await?;
1005+
let (toolchain, source) = cfg.ensure_active_toolchain(force_non_host, true).await?;
10061006
info!("the active toolchain `{toolchain}` has been installed");
1007-
info!("it's active because: {reason}");
1007+
info!("it's active because: {source}");
10081008
} else {
10091009
exit_code &= common::update_all_channels(cfg, opts.force).await?;
10101010
if self_update {
@@ -1099,16 +1099,16 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
10991099
}
11001100

11011101
let installed_toolchains = cfg.list_toolchains()?;
1102-
let active_toolchain_and_reason: Option<(ToolchainName, ActiveReason)> =
1103-
if let Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) =
1102+
let active_toolchain_and_source: Option<(ToolchainName, ActiveSource)> =
1103+
if let Ok(Some((LocalToolchainName::Named(toolchain_name), source))) =
11041104
cfg.maybe_ensure_active_toolchain(None).await
11051105
{
1106-
Some((toolchain_name, reason))
1106+
Some((toolchain_name, source))
11071107
} else {
11081108
None
11091109
};
11101110

1111-
let (active_toolchain_name, _active_reason) = active_toolchain_and_reason
1111+
let (active_toolchain_name, _active_source) = active_toolchain_and_source
11121112
.as_ref()
11131113
.map(|atar| (&atar.0, &atar.1))
11141114
.unzip();
@@ -1172,15 +1172,15 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
11721172

11731173
print_header(&mut t, "active toolchain")?;
11741174

1175-
match active_toolchain_and_reason {
1176-
Some((active_toolchain_name, active_reason)) => {
1177-
let active_toolchain = Toolchain::with_reason(
1175+
match active_toolchain_and_source {
1176+
Some((active_toolchain_name, active_source)) => {
1177+
let active_toolchain = Toolchain::with_source(
11781178
cfg,
11791179
active_toolchain_name.clone().into(),
1180-
&active_reason,
1180+
&active_source,
11811181
)?;
11821182
writeln!(t.lock(), "name: {}", active_toolchain.name())?;
1183-
writeln!(t.lock(), "active because: {active_reason}")?;
1183+
writeln!(t.lock(), "active because: {active_source}")?;
11841184
if verbose {
11851185
writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?;
11861186
writeln!(t.lock(), "path: {}", active_toolchain.path().display())?;
@@ -1214,14 +1214,14 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
12141214
#[tracing::instrument(level = "trace", skip_all)]
12151215
async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
12161216
match cfg.maybe_ensure_active_toolchain(None).await? {
1217-
Some((toolchain_name, reason)) => {
1218-
let toolchain = Toolchain::with_reason(cfg, toolchain_name.clone(), &reason)?;
1217+
Some((toolchain_name, source)) => {
1218+
let toolchain = Toolchain::with_source(cfg, toolchain_name.clone(), &source)?;
12191219
if verbose {
12201220
writeln!(
12211221
cfg.process.stdout().lock(),
12221222
"{}\nactive because: {}\ncompiler: {}\npath: {}",
12231223
toolchain.name(),
1224-
reason,
1224+
source,
12251225
toolchain.rustc_version(),
12261226
toolchain.path().display()
12271227
)?;
@@ -1230,9 +1230,9 @@ async fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::Ex
12301230
cfg.process.stdout().lock(),
12311231
"{} ({})",
12321232
toolchain.name(),
1233-
match reason {
1234-
ActiveReason::Default => &"default" as &dyn fmt::Display,
1235-
_ => &reason,
1233+
match source {
1234+
ActiveSource::Default => &"default" as &dyn fmt::Display,
1235+
_ => &source,
12361236
}
12371237
)?;
12381238
}

src/config.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ impl<T: Into<String>> From<T> for OverrideFile {
8787
}
8888
}
8989

90-
// Represents the reason why the active toolchain is active.
90+
// Represents the source that determined the current active toolchain.
9191
#[derive(Debug)]
92-
pub(crate) enum ActiveReason {
92+
pub(crate) enum ActiveSource {
9393
Default,
9494
Environment,
9595
CommandLine,
9696
OverrideDB(PathBuf),
9797
ToolchainFile(PathBuf),
9898
}
9999

100-
impl Display for ActiveReason {
100+
impl Display for ActiveSource {
101101
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
102102
match self {
103103
Self::Default => write!(f, "it's the default toolchain"),
@@ -486,7 +486,7 @@ impl<'a> Cfg<'a> {
486486
pub(crate) async fn maybe_ensure_active_toolchain(
487487
&self,
488488
force_ensure: Option<bool>,
489-
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
489+
) -> Result<Option<(LocalToolchainName, ActiveSource)>> {
490490
let should_ensure = if let Some(force) = force_ensure {
491491
force
492492
} else {
@@ -505,39 +505,39 @@ impl<'a> Cfg<'a> {
505505
}
506506
}
507507

508-
pub(crate) fn active_toolchain(&self) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
508+
pub(crate) fn active_toolchain(&self) -> Result<Option<(LocalToolchainName, ActiveSource)>> {
509509
Ok(
510-
if let Some((override_config, reason)) = self.find_override_config()? {
511-
Some((override_config.into_local_toolchain_name(), reason))
510+
if let Some((override_config, source)) = self.find_override_config()? {
511+
Some((override_config.into_local_toolchain_name(), source))
512512
} else {
513513
self.get_default()?
514-
.map(|x| (x.into(), ActiveReason::Default))
514+
.map(|x| (x.into(), ActiveSource::Default))
515515
},
516516
)
517517
}
518518

519-
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveReason)>> {
520-
let override_config: Option<(OverrideCfg, ActiveReason)> =
519+
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveSource)>> {
520+
let override_config: Option<(OverrideCfg, ActiveSource)> =
521521
// First check +toolchain override from the command line
522522
if let Some(name) = &self.toolchain_override {
523523
let override_config = name.resolve(&self.get_default_host_triple()?)?.into();
524-
Some((override_config, ActiveReason::CommandLine))
524+
Some((override_config, ActiveSource::CommandLine))
525525
}
526526
// Then check the RUSTUP_TOOLCHAIN environment variable
527527
else if let Some(name) = &self.env_override {
528528
// Because path based toolchain files exist, this has to support
529529
// custom, distributable, and absolute path toolchains otherwise
530530
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
531531
// error when a nested rustup invocation occurs
532-
Some((name.clone().into(), ActiveReason::Environment))
532+
Some((name.clone().into(), ActiveSource::Environment))
533533
}
534534
// Then walk up the directory tree from 'path' looking for either the
535535
// directory in the override database, or a `rust-toolchain{.toml}` file,
536536
// in that order.
537-
else if let Some((override_cfg, active_reason)) = self.settings_file.with(|s| {
537+
else if let Some((override_cfg, active_source)) = self.settings_file.with(|s| {
538538
self.find_override_from_dir_walk(&self.current_dir, s)
539539
})? {
540-
Some((override_cfg, active_reason))
540+
Some((override_cfg, active_source))
541541
}
542542
// Otherwise, there is no override.
543543
else {
@@ -551,13 +551,13 @@ impl<'a> Cfg<'a> {
551551
&self,
552552
dir: &Path,
553553
settings: &Settings,
554-
) -> Result<Option<(OverrideCfg, ActiveReason)>> {
554+
) -> Result<Option<(OverrideCfg, ActiveSource)>> {
555555
let mut dir = Some(dir);
556556

557557
while let Some(d) = dir {
558558
// First check the override database
559559
if let Some(name) = settings.dir_override(d) {
560-
let reason = ActiveReason::OverrideDB(d.to_owned());
560+
let source = ActiveSource::OverrideDB(d.to_owned());
561561
// Note that `rustup override set` fully resolves it's input
562562
// before writing to settings.toml, so resolving here may not
563563
// be strictly necessary (could instead model as ToolchainName).
@@ -567,7 +567,7 @@ impl<'a> Cfg<'a> {
567567
let toolchain_name = ResolvableToolchainName::try_from(name)?
568568
.resolve(&get_default_host_triple(settings, self.process))?;
569569
let override_cfg = toolchain_name.into();
570-
return Ok(Some((override_cfg, reason)));
570+
return Ok(Some((override_cfg, source)));
571571
}
572572

573573
// Then look for 'rust-toolchain' or 'rust-toolchain.toml'
@@ -651,9 +651,9 @@ impl<'a> Cfg<'a> {
651651
}
652652
}
653653

654-
let reason = ActiveReason::ToolchainFile(toolchain_file);
654+
let source = ActiveSource::ToolchainFile(toolchain_file);
655655
let override_cfg = OverrideCfg::from_file(self, override_file)?;
656-
return Ok(Some((override_cfg, reason)));
656+
return Ok(Some((override_cfg, source)));
657657
}
658658

659659
dir = d.parent();
@@ -747,8 +747,8 @@ impl<'a> Cfg<'a> {
747747
&self,
748748
force_non_host: bool,
749749
verbose: bool,
750-
) -> Result<(LocalToolchainName, ActiveReason)> {
751-
if let Some((override_config, reason)) = self.find_override_config()? {
750+
) -> Result<(LocalToolchainName, ActiveSource)> {
751+
if let Some((override_config, source)) = self.find_override_config()? {
752752
let toolchain = override_config.clone().into_local_toolchain_name();
753753
if let OverrideCfg::Official {
754754
toolchain,
@@ -767,18 +767,18 @@ impl<'a> Cfg<'a> {
767767
)
768768
.await?;
769769
} else {
770-
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
770+
Toolchain::with_source(self, toolchain.clone(), &source)?;
771771
}
772-
Ok((toolchain, reason))
772+
Ok((toolchain, source))
773773
} else if let Some(toolchain) = self.get_default()? {
774-
let reason = ActiveReason::Default;
774+
let source = ActiveSource::Default;
775775
if let ToolchainName::Official(desc) = &toolchain {
776776
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
777777
.await?;
778778
} else {
779-
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
779+
Toolchain::with_source(self, toolchain.clone().into(), &source)?;
780780
}
781-
Ok((toolchain.into(), reason))
781+
Ok((toolchain.into(), source))
782782
} else {
783783
Err(no_toolchain_error(self.process))
784784
}

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)