Skip to content

Commit 8f1a1a1

Browse files
committed
Move rustc_version() function into Cfg
1 parent 7d8caa7 commit 8f1a1a1

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/cli/rustup_mode.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -540,25 +540,8 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
540540
Err(err) if err.kind() == DisplayVersion => {
541541
write!(process.stdout().lock(), "{err}")?;
542542
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
543-
544-
#[cfg_attr(feature = "otel", tracing::instrument)]
545-
async fn rustc_version(
546-
current_dir: PathBuf,
547-
process: &Process,
548-
) -> std::result::Result<String, Box<dyn std::error::Error>> {
549-
let cfg = &mut common::set_globals(current_dir, false, true, process)?;
550-
551-
if let Some(t) = process.args().find(|x| x.starts_with('+')) {
552-
trace!("Fetching rustc version from toolchain `{}`", t);
553-
cfg.set_toolchain_override(&ResolvableToolchainName::try_from(&t[1..])?);
554-
}
555-
556-
let toolchain = cfg.find_or_install_active_toolchain().await?.0;
557-
558-
Ok(toolchain.rustc_version())
559-
}
560-
561-
match rustc_version(current_dir, process).await {
543+
let mut cfg = common::set_globals(current_dir, false, true, process)?;
544+
match cfg.active_rustc_version().await {
562545
Ok(version) => info!("The currently active `rustc` version is `{}`", version),
563546
Err(err) => trace!("Wanted to tell you the current rustc version, too, but ran into this error: {}", err),
564547
}
@@ -583,6 +566,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
583566
Err(err)
584567
}
585568
}?;
569+
586570
let cfg = &mut common::set_globals(current_dir, matches.verbose, matches.quiet, process)?;
587571

588572
if let Some(t) = &matches.plus_toolchain {

src/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,20 @@ impl<'a> Cfg<'a> {
702702
}
703703
}
704704

705+
#[cfg_attr(feature = "otel", tracing::instrument)]
706+
pub(crate) async fn active_rustc_version(&mut self) -> Result<String> {
707+
if let Some(t) = self.process.args().find(|x| x.starts_with('+')) {
708+
trace!("Fetching rustc version from toolchain `{}`", t);
709+
self.set_toolchain_override(&ResolvableToolchainName::try_from(&t[1..])?);
710+
}
711+
712+
Ok(self
713+
.find_or_install_active_toolchain()
714+
.await?
715+
.0
716+
.rustc_version())
717+
}
718+
705719
pub(crate) async fn find_or_install_active_toolchain(
706720
&'a self,
707721
) -> Result<(Toolchain<'a>, ActiveReason)> {

0 commit comments

Comments
 (0)