Skip to content

Commit 41f0298

Browse files
committed
DON'T MERGE[ci skip]: demonstrate if_let_rescope auto migration
1 parent bfdb0d9 commit 41f0298

File tree

10 files changed

+62
-71
lines changed

10 files changed

+62
-71
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ url = "2.4"
155155
walkdir = "2"
156156

157157
[workspace.lints.rust]
158-
rust_2018_idioms = "deny"
158+
rust_2018_idioms = { level = "deny", priority = -1 }
159+
if_let_rescope = { level = "warn", priority = -2 }
159160

160161
[workspace.lints.clippy]
161162
# `dbg!()` and `todo!()` clearly shouldn't make it to production:

src/cli/common.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,12 @@ pub(crate) fn list_toolchains(
417417
} else {
418418
let default_toolchain_name = cfg.get_default()?;
419419
let active_toolchain_name: Option<ToolchainName> =
420-
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
421-
cfg.find_active_toolchain()
422-
{
420+
match cfg.find_active_toolchain()
421+
{ Ok(Some((LocalToolchainName::Named(toolchain), _reason))) => {
423422
Some(toolchain)
424-
} else {
423+
} _ => {
425424
None
426-
};
425+
}};
427426

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

src/cli/rustup_mode.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ async fn default_(
727727
) -> Result<utils::ExitCode> {
728728
common::warn_if_host_is_emulated(cfg.process);
729729

730-
if let Some(toolchain) = toolchain {
730+
match toolchain { Some(toolchain) => {
731731
match toolchain.to_owned() {
732732
MaybeResolvableToolchainName::None => {
733733
cfg.set_default(None)?;
@@ -756,12 +756,12 @@ async fn default_(
756756
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
757757
}
758758
}
759-
} else {
759+
} _ => {
760760
let default_toolchain = cfg
761761
.get_default()?
762762
.ok_or_else(|| anyhow!("no default toolchain is configured"))?;
763763
writeln!(cfg.process.stdout().lock(), "{default_toolchain} (default)")?;
764-
}
764+
}}
765765

766766
Ok(utils::ExitCode(0))
767767
}
@@ -961,13 +961,12 @@ fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode> {
961961

962962
let installed_toolchains = cfg.list_toolchains()?;
963963
let active_toolchain_and_reason: Option<(ToolchainName, ActiveReason)> =
964-
if let Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) =
965-
cfg.find_active_toolchain()
966-
{
964+
match cfg.find_active_toolchain()
965+
{ Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) => {
967966
Some((toolchain_name, reason))
968-
} else {
967+
} _ => {
969968
None
970-
};
969+
}};
971970

972971
let (active_toolchain_name, _active_reason) = active_toolchain_and_reason
973972
.as_ref()

src/config.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -518,42 +518,34 @@ impl<'a> Cfg<'a> {
518518
&self,
519519
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
520520
Ok(
521-
if let Some((override_config, reason)) = self.find_override_config()? {
521+
match self.find_override_config()? { Some((override_config, reason)) => {
522522
Some((override_config.into_local_toolchain_name(), reason))
523-
} else {
523+
} _ => {
524524
self.get_default()?
525525
.map(|x| (x.into(), ActiveReason::Default))
526-
},
526+
}},
527527
)
528528
}
529529

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

558550
Ok(override_config)
559551
}
@@ -753,15 +745,15 @@ impl<'a> Cfg<'a> {
753745
force_non_host: bool,
754746
verbose: bool,
755747
) -> Result<(LocalToolchainName, ActiveReason)> {
756-
if let Some((override_config, reason)) = self.find_override_config()? {
748+
match self.find_override_config()? { Some((override_config, reason)) => {
757749
let toolchain = override_config.clone().into_local_toolchain_name();
758-
if let OverrideCfg::Official {
750+
match override_config
751+
{ OverrideCfg::Official {
759752
toolchain,
760753
components,
761754
targets,
762755
profile,
763-
} = override_config
764-
{
756+
} => {
765757
self.ensure_installed(
766758
&toolchain,
767759
components,
@@ -771,22 +763,22 @@ impl<'a> Cfg<'a> {
771763
verbose,
772764
)
773765
.await?;
774-
} else {
766+
} _ => {
775767
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
776-
}
768+
}}
777769
Ok((toolchain, reason))
778-
} else if let Some(toolchain) = self.get_default()? {
770+
} _ => { match self.get_default()? { Some(toolchain) => {
779771
let reason = ActiveReason::Default;
780-
if let ToolchainName::Official(desc) = &toolchain {
772+
match &toolchain { ToolchainName::Official(desc) => {
781773
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
782774
.await?;
783-
} else {
775+
} _ => {
784776
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
785-
}
777+
}}
786778
Ok((toolchain.into(), reason))
787-
} else {
779+
} _ => {
788780
Err(no_toolchain_error(self.process))
789-
}
781+
}}}}
790782
}
791783

792784
// Returns a Toolchain matching the given ToolchainDesc, installing it and
@@ -894,11 +886,11 @@ impl<'a> Cfg<'a> {
894886
self.list_toolchains()?
895887
.into_iter()
896888
.filter_map(|t| {
897-
if let ToolchainName::Official(desc) = t {
889+
match t { ToolchainName::Official(desc) => {
898890
Some(desc)
899-
} else {
891+
} _ => {
900892
None
901-
}
893+
}}
902894
})
903895
.filter(ToolchainDesc::is_tracking)
904896
.map(|n| {

src/diskio/immediate.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ImmediateUnpacker {
3838
fn deque(&self) -> Box<dyn Iterator<Item = CompletedIo>> {
3939
let mut guard = self.incremental_state.lock().unwrap();
4040
// incremental file in progress
41-
if let Some(ref mut state) = *guard {
41+
match *guard { Some(ref mut state) => {
4242
// Case 1: pending errors
4343
if state.finished {
4444
let mut item = state.item.take().unwrap();
@@ -59,9 +59,9 @@ impl ImmediateUnpacker {
5959
completed_chunks.append(&mut state.completed_chunks);
6060
Box::new(completed_chunks.into_iter().map(CompletedIo::Chunk))
6161
}
62-
} else {
62+
} _ => {
6363
Box::new(None.into_iter())
64-
}
64+
}}
6565
}
6666
}
6767

@@ -187,13 +187,13 @@ impl IncrementalFileWriter {
187187
Ok(v) => v,
188188
Err(e) => {
189189
let mut state = self.state.lock().unwrap();
190-
if let Some(ref mut state) = *state {
190+
match *state { Some(ref mut state) => {
191191
state.err.replace(Err(e));
192192
state.finished = true;
193193
false
194-
} else {
194+
} _ => {
195195
false
196-
}
196+
}}
197197
}
198198
}
199199
}
@@ -203,7 +203,7 @@ impl IncrementalFileWriter {
203203
let Some(ref mut state) = *state else {
204204
unreachable!()
205205
};
206-
if let Some(ref mut file) = self.file.as_mut() {
206+
match self.file.as_mut() { Some(ref mut file) => {
207207
// Length 0 vector is used for clean EOF signalling.
208208
if chunk.is_empty() {
209209
trace_scoped!("close", "name:": self.path_display);
@@ -216,8 +216,8 @@ impl IncrementalFileWriter {
216216
state.completed_chunks.push(chunk.len());
217217
}
218218
Ok(true)
219-
} else {
219+
} _ => {
220220
Ok(false)
221-
}
221+
}}
222222
}
223223
}

src/dist/download.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ impl<'a> DownloadCfg<'a> {
162162

163163
if let Some(hash_file) = update_hash {
164164
if utils::is_file(hash_file) {
165-
if let Ok(contents) = utils::read_file("update hash", hash_file) {
165+
match utils::read_file("update hash", hash_file) { Ok(contents) => {
166166
if contents == partial_hash {
167167
// Skip download, update hash matches
168168
return Ok(None);
169169
}
170-
} else {
170+
} _ => {
171171
(self.notify_handler)(Notification::CantReadUpdateHash(hash_file));
172-
}
172+
}}
173173
} else {
174174
(self.notify_handler)(Notification::NoUpdateHash(hash_file));
175175
}

src/dist/manifestation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,15 @@ impl Manifestation {
369369
// component name plus the target triple.
370370
let name = component.name_in_manifest();
371371
let short_name = component.short_name_in_manifest();
372-
if let Some(c) = self.installation.find(&name)? {
372+
match self.installation.find(&name)? { Some(c) => {
373373
tx = c.uninstall(tx, process)?;
374-
} else if let Some(c) = self.installation.find(short_name)? {
374+
} _ => { match self.installation.find(short_name)? { Some(c) => {
375375
tx = c.uninstall(tx, process)?;
376-
} else {
376+
} _ => {
377377
notify_handler(Notification::MissingInstalledComponent(
378378
&component.short_name(manifest),
379379
));
380-
}
380+
}}}}
381381

382382
Ok(tx)
383383
}

src/dist/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,13 +971,13 @@ pub(crate) async fn update_from_dist(
971971

972972
if try_next < last_manifest {
973973
// Wouldn't be an update if we go further back than the user's current nightly.
974-
if let Some(e) = first_err {
974+
match first_err { Some(e) => {
975975
break Err(e);
976-
} else {
976+
} _ => {
977977
// In this case, all newer nightlies are missing, which means there are no
978978
// updates, so the user is already at the latest nightly.
979979
break Ok(None);
980-
}
980+
}}
981981
}
982982

983983
toolchain.date = Some(try_next.format("%Y-%m-%d").to_string());

src/toolchain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,16 @@ impl<'a> Toolchain<'a> {
353353
#[cfg_attr(feature="otel", tracing::instrument(err,fields(binary, recursion=self.cfg.process.var("RUST_RECURSION_COUNT").ok())))]
354354
fn create_command<T: AsRef<OsStr> + Debug>(&self, binary: T) -> Result<Command, anyhow::Error> {
355355
// Create the path to this binary within the current toolchain sysroot
356-
let binary = if let Some(binary_str) = binary.as_ref().to_str() {
356+
let binary = match binary.as_ref().to_str() { Some(binary_str) => {
357357
if binary_str.to_lowercase().ends_with(EXE_SUFFIX) {
358358
binary.as_ref().to_owned()
359359
} else {
360360
OsString::from(format!("{binary_str}{EXE_SUFFIX}"))
361361
}
362-
} else {
362+
} _ => {
363363
// Very weird case. Non-unicode command.
364364
binary.as_ref().to_owned()
365-
};
365+
}};
366366

367367
let bin_path = self.path.join("bin").join(&binary);
368368
let path = if utils::is_file(&bin_path) {

src/toolchain/distributable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a> DistributableToolchain<'a> {
231231
const MAX_DISTANCE: usize = 3;
232232

233233
let components = manifest.query_components(&self.desc, config);
234-
if let Ok(components) = components {
234+
match components { Ok(components) => {
235235
let short_name_distance = components
236236
.iter()
237237
.filter(|c| !only_installed || c.installed)
@@ -296,9 +296,9 @@ impl<'a> DistributableToolchain<'a> {
296296
} else {
297297
Some(closest_match)
298298
}
299-
} else {
299+
} _ => {
300300
None
301-
}
301+
}}
302302
}
303303

304304
#[tracing::instrument(level = "trace", skip_all)]

0 commit comments

Comments
 (0)