Skip to content

Commit 85c63ce

Browse files
committed
DON'T MERGE[ci skip]: demonstrate if_let_rescope auto migration
1 parent 39526f9 commit 85c63ce

File tree

11 files changed

+80
-89
lines changed

11 files changed

+80
-89
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: 18 additions & 18 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

@@ -81,7 +81,7 @@ impl Executor for ImmediateUnpacker {
8181
// If there is a pending error, return it, otherwise stash the
8282
// Item for eventual return when the file is finished.
8383
let mut guard = self.incremental_state.lock().unwrap();
84-
if let Some(ref mut state) = *guard {
84+
match *guard { Some(ref mut state) => {
8585
if state.err.is_some() {
8686
let err = state.err.take().unwrap();
8787
item.result = err;
@@ -94,9 +94,9 @@ impl Executor for ImmediateUnpacker {
9494
state.item = Some(item);
9595
Box::new(None.into_iter())
9696
}
97-
} else {
97+
} _ => {
9898
unreachable!();
99-
}
99+
}}
100100
};
101101
}
102102
};
@@ -181,30 +181,30 @@ impl IncrementalFileWriter {
181181
if (self.state.lock().unwrap()).is_none() {
182182
return false;
183183
}
184-
let chunk = if let FileBuffer::Immediate(v) = chunk {
184+
let chunk = match chunk { FileBuffer::Immediate(v) => {
185185
v
186-
} else {
186+
} _ => {
187187
unreachable!()
188-
};
188+
}};
189189
match self.write(chunk) {
190190
Ok(v) => v,
191191
Err(e) => {
192192
let mut state = self.state.lock().unwrap();
193-
if let Some(ref mut state) = *state {
193+
match *state { Some(ref mut state) => {
194194
state.err.replace(Err(e));
195195
state.finished = true;
196196
false
197-
} else {
197+
} _ => {
198198
false
199-
}
199+
}}
200200
}
201201
}
202202
}
203203

204204
fn write(&mut self, chunk: Vec<u8>) -> std::result::Result<bool, io::Error> {
205205
let mut state = self.state.lock().unwrap();
206-
if let Some(ref mut state) = *state {
207-
if let Some(ref mut file) = self.file.as_mut() {
206+
match *state { Some(ref mut state) => {
207+
match self.file.as_mut() { Some(ref mut file) => {
208208
// Length 0 vector is used for clean EOF signalling.
209209
if chunk.is_empty() {
210210
trace_scoped!("close", "name:": self.path_display);
@@ -217,11 +217,11 @@ impl IncrementalFileWriter {
217217
state.completed_chunks.push(chunk.len());
218218
}
219219
Ok(true)
220-
} else {
220+
} _ => {
221221
Ok(false)
222-
}
223-
} else {
222+
}}
223+
} _ => {
224224
unreachable!();
225-
}
225+
}}
226226
}
227227
}

src/dist/component/package.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ fn filter_result(op: &mut CompletedIo) -> io::Result<()> {
229229
// mkdir of e.g. ~/.rustup already existing is just fine;
230230
// for others it would be better to know whether it is
231231
// expected to exist or not -so put a flag in the state.
232-
if let Kind::Directory = op.kind {
232+
match op.kind { Kind::Directory => {
233233
Ok(())
234-
} else {
234+
} _ => {
235235
Err(e)
236-
}
236+
}}
237237
}
238238
_ => Err(e),
239239
},
@@ -454,7 +454,7 @@ fn unpack_without_first_dir<R: Read>(
454454

455455
let item = loop {
456456
// Create the full path to the entry if it does not exist already
457-
if let Some(parent) = item.full_path.to_owned().parent() {
457+
match item.full_path.to_owned().parent() { Some(parent) => {
458458
match directories.get_mut(parent) {
459459
None => {
460460
// Tar has item before containing directory
@@ -485,10 +485,10 @@ fn unpack_without_first_dir<R: Read>(
485485
}
486486
}
487487
}
488-
} else {
488+
} _ => {
489489
// We should never see a path with no parent.
490490
panic!();
491-
}
491+
}}
492492
};
493493

494494
if let Some(item) = item {

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ impl FromStr for ParsedToolchainDesc {
335335
}
336336
});
337337

338-
if let Some(d) = d {
338+
match d { Some(d) => {
339339
Ok(d)
340-
} else {
340+
} _ => {
341341
Err(RustupError::InvalidToolchainName(desc.to_string()).into())
342-
}
342+
}}
343343
}
344344
}
345345

@@ -975,13 +975,13 @@ pub(crate) async fn update_from_dist(
975975

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

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

0 commit comments

Comments
 (0)