Skip to content

Commit d84e07a

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

File tree

11 files changed

+162
-69
lines changed

11 files changed

+162
-69
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: 55 additions & 7 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,6 +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+
<<<<<<< HEAD
8485
let Some(ref mut state) = *guard else {
8586
unreachable!()
8687
};
@@ -96,6 +97,24 @@ impl Executor for ImmediateUnpacker {
9697
state.item = Some(item);
9798
Box::new(None.into_iter())
9899
}
100+
=======
101+
match *guard { Some(ref mut state) => {
102+
if state.err.is_some() {
103+
let err = state.err.take().unwrap();
104+
item.result = err;
105+
item.finish = item
106+
.start
107+
.map(|s| Instant::now().saturating_duration_since(s));
108+
*guard = None;
109+
Box::new(Some(CompletedIo::Item(item)).into_iter())
110+
} else {
111+
state.item = Some(item);
112+
Box::new(None.into_iter())
113+
}
114+
} _ => {
115+
unreachable!();
116+
}}
117+
>>>>>>> 85c63ce1 (DON'T MERGE[ci skip]: demonstrate `if_let_rescope` auto migration)
99118
};
100119
}
101120
};
@@ -180,26 +199,33 @@ impl IncrementalFileWriter {
180199
if (self.state.lock().unwrap()).is_none() {
181200
return false;
182201
}
202+
<<<<<<< HEAD
183203
let FileBuffer::Immediate(chunk) = chunk else {
204+
=======
205+
let chunk = match chunk { FileBuffer::Immediate(v) => {
206+
v
207+
} _ => {
208+
>>>>>>> 85c63ce1 (DON'T MERGE[ci skip]: demonstrate `if_let_rescope` auto migration)
184209
unreachable!()
185-
};
210+
}};
186211
match self.write(chunk) {
187212
Ok(v) => v,
188213
Err(e) => {
189214
let mut state = self.state.lock().unwrap();
190-
if let Some(ref mut state) = *state {
215+
match *state { Some(ref mut state) => {
191216
state.err.replace(Err(e));
192217
state.finished = true;
193218
false
194-
} else {
219+
} _ => {
195220
false
196-
}
221+
}}
197222
}
198223
}
199224
}
200225

201226
fn write(&mut self, chunk: Vec<u8>) -> std::result::Result<bool, io::Error> {
202227
let mut state = self.state.lock().unwrap();
228+
<<<<<<< HEAD
203229
let Some(ref mut state) = *state else {
204230
unreachable!()
205231
};
@@ -219,5 +245,27 @@ impl IncrementalFileWriter {
219245
} else {
220246
Ok(false)
221247
}
248+
=======
249+
match *state { Some(ref mut state) => {
250+
match self.file.as_mut() { Some(ref mut file) => {
251+
// Length 0 vector is used for clean EOF signalling.
252+
if chunk.is_empty() {
253+
trace_scoped!("close", "name:": self.path_display);
254+
drop(std::mem::take(&mut self.file));
255+
state.finished = true;
256+
} else {
257+
trace_scoped!("write_segment", "name": self.path_display, "len": chunk.len());
258+
file.write_all(&chunk)?;
259+
260+
state.completed_chunks.push(chunk.len());
261+
}
262+
Ok(true)
263+
} _ => {
264+
Ok(false)
265+
}}
266+
} _ => {
267+
unreachable!();
268+
}}
269+
>>>>>>> 85c63ce1 (DON'T MERGE[ci skip]: demonstrate `if_let_rescope` auto migration)
222270
}
223271
}

src/dist/component/package.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,18 @@ 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+
<<<<<<< HEAD
232233
match op.kind {
233234
Kind::Directory => Ok(()),
234235
_ => Err(e),
235236
}
237+
=======
238+
match op.kind { Kind::Directory => {
239+
Ok(())
240+
} _ => {
241+
Err(e)
242+
}}
243+
>>>>>>> 85c63ce1 (DON'T MERGE[ci skip]: demonstrate `if_let_rescope` auto migration)
236244
}
237245
_ => Err(e),
238246
},
@@ -453,6 +461,7 @@ fn unpack_without_first_dir<R: Read>(
453461

454462
let item = loop {
455463
// Create the full path to the entry if it does not exist already
464+
<<<<<<< HEAD
456465
let full_path = item.full_path.to_owned();
457466
let Some(parent) = full_path.parent() else {
458467
// We should never see a path with no parent.
@@ -488,6 +497,43 @@ fn unpack_without_first_dir<R: Read>(
488497
}
489498
}
490499
}
500+
=======
501+
match item.full_path.to_owned().parent() { Some(parent) => {
502+
match directories.get_mut(parent) {
503+
None => {
504+
// Tar has item before containing directory
505+
// Complain about this so we can see if these exist.
506+
writeln!(
507+
process.stderr().lock(),
508+
"Unexpected: missing parent '{}' for '{}'",
509+
parent.display(),
510+
entry.path()?.display()
511+
)?;
512+
directories.insert(parent.to_owned(), DirStatus::Pending(vec![item]));
513+
item = Item::make_dir(parent.to_owned(), 0o755);
514+
// Check the parent's parent
515+
continue;
516+
}
517+
Some(DirStatus::Exists) => {
518+
break Some(item);
519+
}
520+
Some(DirStatus::Pending(pending)) => {
521+
// Parent dir is being made
522+
pending.push(item);
523+
if incremental_file_sender.is_none() {
524+
// take next item from tar
525+
continue 'entries;
526+
} else {
527+
// don't submit a new item for processing, but do be ready to feed data to the incremental file.
528+
break None;
529+
}
530+
}
531+
}
532+
} _ => {
533+
// We should never see a path with no parent.
534+
panic!();
535+
}}
536+
>>>>>>> 85c63ce1 (DON'T MERGE[ci skip]: demonstrate `if_let_rescope` auto migration)
491537
};
492538

493539
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
}

0 commit comments

Comments
 (0)