Skip to content

Commit f285137

Browse files
committed
chore(edition): perform automatic migration to Rust 2024
1 parent f375ccb commit f285137

File tree

16 files changed

+356
-317
lines changed

16 files changed

+356
-317
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ members = ["download"]
131131

132132
[workspace.package]
133133
version = "1.28.0"
134-
edition = "2021"
134+
edition = "2024"
135135
license = "MIT OR Apache-2.0"
136136

137137
[workspace.dependencies]

src/cli/common.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,10 @@ pub(crate) fn list_toolchains(
416416
writeln!(cfg.process.stdout().lock(), "no installed toolchains")?;
417417
} else {
418418
let default_toolchain_name = cfg.get_default()?;
419-
let active_toolchain_name: Option<ToolchainName> =
420-
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
421-
cfg.find_active_toolchain()
422-
{
423-
Some(toolchain)
424-
} else {
425-
None
426-
};
419+
let active_toolchain_name: Option<ToolchainName> = match cfg.find_active_toolchain() {
420+
Ok(Some((LocalToolchainName::Named(toolchain), _reason))) => Some(toolchain),
421+
_ => None,
422+
};
427423

428424
for toolchain in toolchains {
429425
let is_default_toolchain = default_toolchain_name.as_ref() == Some(&toolchain);

src/cli/log.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{process::Process, utils::notify::NotificationLevel};
1919
pub fn tracing_subscriber(
2020
process: &Process,
2121
) -> (
22-
impl tracing::Subscriber,
22+
impl tracing::Subscriber + use<>,
2323
reload::Handle<EnvFilter, Registry>,
2424
) {
2525
#[cfg(feature = "otel")]
@@ -44,7 +44,7 @@ pub fn tracing_subscriber(
4444
/// When the `RUSTUP_LOG` environment variable is present, a standard [`tracing_subscriber`]
4545
/// formatter will be used according to the filtering directives set in its value.
4646
/// Otherwise, this logger will use [`EventFormatter`] to mimic "classic" Rustup `stderr` output.
47-
fn console_logger<S>(process: &Process) -> (impl Layer<S>, reload::Handle<EnvFilter, S>)
47+
fn console_logger<S>(process: &Process) -> (impl Layer<S> + use<S>, reload::Handle<EnvFilter, S>)
4848
where
4949
S: Subscriber + for<'span> LookupSpan<'span>,
5050
{
@@ -128,7 +128,7 @@ impl NotificationLevel {
128128
/// A [`tracing::Subscriber`] [`Layer`][`tracing_subscriber::Layer`] that corresponds to Rustup's
129129
/// optional `opentelemetry` (a.k.a. `otel`) feature.
130130
#[cfg(feature = "otel")]
131-
fn telemetry<S>(process: &Process) -> impl Layer<S>
131+
fn telemetry<S>(process: &Process) -> impl Layer<S> + use<S>
132132
where
133133
S: Subscriber + for<'span> LookupSpan<'span>,
134134
{

src/cli/rustup_mode.rs

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -723,40 +723,47 @@ async fn default_(
723723
) -> Result<utils::ExitCode> {
724724
common::warn_if_host_is_emulated(cfg.process);
725725

726-
if let Some(toolchain) = toolchain {
727-
match toolchain.to_owned() {
728-
MaybeResolvableToolchainName::None => {
729-
cfg.set_default(None)?;
730-
}
731-
MaybeResolvableToolchainName::Some(ResolvableToolchainName::Custom(toolchain_name)) => {
732-
Toolchain::new(cfg, (&toolchain_name).into())?;
733-
cfg.set_default(Some(&toolchain_name.into()))?;
734-
}
735-
MaybeResolvableToolchainName::Some(ResolvableToolchainName::Official(toolchain)) => {
736-
let desc = toolchain.resolve(&cfg.get_default_host_triple()?)?;
737-
let status = cfg
738-
.ensure_installed(&desc, vec![], vec![], None, force_non_host, true)
739-
.await?
740-
.0;
726+
match toolchain {
727+
Some(toolchain) => {
728+
match toolchain.to_owned() {
729+
MaybeResolvableToolchainName::None => {
730+
cfg.set_default(None)?;
731+
}
732+
MaybeResolvableToolchainName::Some(ResolvableToolchainName::Custom(
733+
toolchain_name,
734+
)) => {
735+
Toolchain::new(cfg, (&toolchain_name).into())?;
736+
cfg.set_default(Some(&toolchain_name.into()))?;
737+
}
738+
MaybeResolvableToolchainName::Some(ResolvableToolchainName::Official(
739+
toolchain,
740+
)) => {
741+
let desc = toolchain.resolve(&cfg.get_default_host_triple()?)?;
742+
let status = cfg
743+
.ensure_installed(&desc, vec![], vec![], None, force_non_host, true)
744+
.await?
745+
.0;
741746

742-
cfg.set_default(Some(&(&desc).into()))?;
747+
cfg.set_default(Some(&(&desc).into()))?;
743748

744-
writeln!(cfg.process.stdout().lock())?;
749+
writeln!(cfg.process.stdout().lock())?;
745750

746-
common::show_channel_update(cfg, PackageUpdate::Toolchain(desc), Ok(status))?;
747-
}
748-
};
751+
common::show_channel_update(cfg, PackageUpdate::Toolchain(desc), Ok(status))?;
752+
}
753+
};
749754

750-
if let Some((toolchain, reason)) = cfg.find_active_toolchain()? {
751-
if !matches!(reason, ActiveReason::Default) {
752-
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
755+
if let Some((toolchain, reason)) = cfg.find_active_toolchain()? {
756+
if !matches!(reason, ActiveReason::Default) {
757+
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
758+
}
753759
}
754760
}
755-
} else {
756-
let default_toolchain = cfg
757-
.get_default()?
758-
.ok_or_else(|| anyhow!("no default toolchain is configured"))?;
759-
writeln!(cfg.process.stdout().lock(), "{default_toolchain} (default)")?;
761+
_ => {
762+
let default_toolchain = cfg
763+
.get_default()?
764+
.ok_or_else(|| anyhow!("no default toolchain is configured"))?;
765+
writeln!(cfg.process.stdout().lock(), "{default_toolchain} (default)")?;
766+
}
760767
}
761768

762769
Ok(utils::ExitCode(0))
@@ -957,12 +964,11 @@ fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
957964

958965
let installed_toolchains = cfg.list_toolchains()?;
959966
let active_toolchain_and_reason: Option<(ToolchainName, ActiveReason)> =
960-
if let Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) =
961-
cfg.find_active_toolchain()
962-
{
963-
Some((toolchain_name, reason))
964-
} else {
965-
None
967+
match cfg.find_active_toolchain() {
968+
Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) => {
969+
Some((toolchain_name, reason))
970+
}
971+
_ => None,
966972
};
967973

968974
let (active_toolchain_name, _active_reason) = active_toolchain_and_reason
@@ -1408,7 +1414,7 @@ macro_rules! docs_data {
14081414
(
14091415
$(
14101416
$( #[$meta:meta] )*
1411-
($ident:ident, $help:expr, $path:expr $(,)?)
1417+
($ident:ident, $help:expr_2021, $path:expr_2021 $(,)?)
14121418
),+ $(,)?
14131419
) => {
14141420
#[derive(Debug, Args)]

src/config.rs

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -515,43 +515,35 @@ impl<'a> Cfg<'a> {
515515
pub(crate) fn find_active_toolchain(
516516
&self,
517517
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
518-
Ok(
519-
if let Some((override_config, reason)) = self.find_override_config()? {
518+
Ok(match self.find_override_config()? {
519+
Some((override_config, reason)) => {
520520
Some((override_config.into_local_toolchain_name(), reason))
521-
} else {
522-
self.get_default()?
523-
.map(|x| (x.into(), ActiveReason::Default))
524-
},
525-
)
521+
}
522+
_ => self
523+
.get_default()?
524+
.map(|x| (x.into(), ActiveReason::Default)),
525+
})
526526
}
527527

528528
fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveReason)>> {
529529
let override_config: Option<(OverrideCfg, ActiveReason)> =
530530
// First check +toolchain override from the command line
531-
if let Some(ref name) = self.toolchain_override {
531+
match self.toolchain_override { Some(ref name) => {
532532
let override_config = name.resolve(&self.get_default_host_triple()?)?.into();
533533
Some((override_config, ActiveReason::CommandLine))
534-
}
535-
// Then check the RUSTUP_TOOLCHAIN environment variable
536-
else if let Some(ref name) = self.env_override {
534+
} _ => { match self.env_override { Some(ref name) => {
537535
// Because path based toolchain files exist, this has to support
538536
// custom, distributable, and absolute path toolchains otherwise
539537
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
540538
// error when a nested rustup invocation occurs
541539
Some((name.clone().into(), ActiveReason::Environment))
542-
}
543-
// Then walk up the directory tree from 'path' looking for either the
544-
// directory in the override database, or a `rust-toolchain{.toml}` file,
545-
// in that order.
546-
else if let Some((override_cfg, active_reason)) = self.settings_file.with(|s| {
540+
} _ => { match self.settings_file.with(|s| {
547541
self.find_override_from_dir_walk(&self.current_dir, s)
548-
})? {
542+
})? { Some((override_cfg, active_reason)) => {
549543
Some((override_cfg, active_reason))
550-
}
551-
// Otherwise, there is no override.
552-
else {
544+
} _ => {
553545
None
554-
};
546+
}}}}}};
555547

556548
Ok(override_config)
557549
}
@@ -751,39 +743,55 @@ impl<'a> Cfg<'a> {
751743
force_non_host: bool,
752744
verbose: bool,
753745
) -> Result<(LocalToolchainName, ActiveReason)> {
754-
if let Some((override_config, reason)) = self.find_override_config()? {
755-
let toolchain = override_config.clone().into_local_toolchain_name();
756-
if let OverrideCfg::Official {
757-
toolchain,
758-
components,
759-
targets,
760-
profile,
761-
} = override_config
762-
{
763-
self.ensure_installed(
764-
&toolchain,
765-
components,
766-
targets,
767-
profile,
768-
force_non_host,
769-
verbose,
770-
)
771-
.await?;
772-
} else {
773-
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
774-
}
775-
Ok((toolchain, reason))
776-
} else if let Some(toolchain) = self.get_default()? {
777-
let reason = ActiveReason::Default;
778-
if let ToolchainName::Official(desc) = &toolchain {
779-
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
780-
.await?;
781-
} else {
782-
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
746+
match self.find_override_config()? {
747+
Some((override_config, reason)) => {
748+
let toolchain = override_config.clone().into_local_toolchain_name();
749+
match override_config {
750+
OverrideCfg::Official {
751+
toolchain,
752+
components,
753+
targets,
754+
profile,
755+
} => {
756+
self.ensure_installed(
757+
&toolchain,
758+
components,
759+
targets,
760+
profile,
761+
force_non_host,
762+
verbose,
763+
)
764+
.await?;
765+
}
766+
_ => {
767+
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
768+
}
769+
}
770+
Ok((toolchain, reason))
783771
}
784-
Ok((toolchain.into(), reason))
785-
} else {
786-
Err(no_toolchain_error(self.process))
772+
_ => match self.get_default()? {
773+
Some(toolchain) => {
774+
let reason = ActiveReason::Default;
775+
match &toolchain {
776+
ToolchainName::Official(desc) => {
777+
self.ensure_installed(
778+
desc,
779+
vec![],
780+
vec![],
781+
None,
782+
force_non_host,
783+
verbose,
784+
)
785+
.await?;
786+
}
787+
_ => {
788+
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
789+
}
790+
}
791+
Ok((toolchain.into(), reason))
792+
}
793+
_ => Err(no_toolchain_error(self.process)),
794+
},
787795
}
788796
}
789797

@@ -891,12 +899,9 @@ impl<'a> Cfg<'a> {
891899
pub(crate) fn list_channels(&self) -> Result<Vec<(ToolchainDesc, DistributableToolchain<'_>)>> {
892900
self.list_toolchains()?
893901
.into_iter()
894-
.filter_map(|t| {
895-
if let ToolchainName::Official(desc) = t {
896-
Some(desc)
897-
} else {
898-
None
899-
}
902+
.filter_map(|t| match t {
903+
ToolchainName::Official(desc) => Some(desc),
904+
_ => None,
900905
})
901906
.filter(ToolchainDesc::is_tracking)
902907
.map(|n| {

0 commit comments

Comments
 (0)