Skip to content

DON'T MERGE[ci skip]: demonstrate if_let_rescope auto migration #4192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ url = "2.4"
walkdir = "2"

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

[workspace.lints.clippy]
# `dbg!()` and `todo!()` clearly shouldn't make it to production:
Expand Down
9 changes: 4 additions & 5 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,12 @@ pub(crate) fn list_toolchains(
} else {
let default_toolchain_name = cfg.get_default()?;
let active_toolchain_name: Option<ToolchainName> =
if let Ok(Some((LocalToolchainName::Named(toolchain), _reason))) =
cfg.find_active_toolchain()
{
match cfg.find_active_toolchain()
{ Ok(Some((LocalToolchainName::Named(toolchain), _reason))) => {
Some(toolchain)
} else {
} _ => {
None
};
}};

for toolchain in toolchains {
let is_default_toolchain = default_toolchain_name.as_ref() == Some(&toolchain);
Expand Down
15 changes: 7 additions & 8 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ async fn default_(
) -> Result<utils::ExitCode> {
common::warn_if_host_is_emulated(cfg.process);

if let Some(toolchain) = toolchain {
match toolchain { Some(toolchain) => {
match toolchain.to_owned() {
MaybeResolvableToolchainName::None => {
cfg.set_default(None)?;
Expand Down Expand Up @@ -756,12 +756,12 @@ async fn default_(
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
}
}
} else {
} _ => {
let default_toolchain = cfg
.get_default()?
.ok_or_else(|| anyhow!("no default toolchain is configured"))?;
writeln!(cfg.process.stdout().lock(), "{default_toolchain} (default)")?;
}
}}

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

let installed_toolchains = cfg.list_toolchains()?;
let active_toolchain_and_reason: Option<(ToolchainName, ActiveReason)> =
if let Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) =
cfg.find_active_toolchain()
{
match cfg.find_active_toolchain()
{ Ok(Some((LocalToolchainName::Named(toolchain_name), reason))) => {
Some((toolchain_name, reason))
} else {
} _ => {
None
};
}};

let (active_toolchain_name, _active_reason) = active_toolchain_and_reason
.as_ref()
Expand Down
56 changes: 24 additions & 32 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,42 +518,34 @@ impl<'a> Cfg<'a> {
&self,
) -> Result<Option<(LocalToolchainName, ActiveReason)>> {
Ok(
if let Some((override_config, reason)) = self.find_override_config()? {
match self.find_override_config()? { Some((override_config, reason)) => {
Some((override_config.into_local_toolchain_name(), reason))
} else {
} _ => {
self.get_default()?
.map(|x| (x.into(), ActiveReason::Default))
},
}},
)
}

fn find_override_config(&self) -> Result<Option<(OverrideCfg, ActiveReason)>> {
let override_config: Option<(OverrideCfg, ActiveReason)> =
// First check +toolchain override from the command line
if let Some(ref name) = self.toolchain_override {
match self.toolchain_override { Some(ref name) => {
let override_config = name.resolve(&self.get_default_host_triple()?)?.into();
Some((override_config, ActiveReason::CommandLine))
}
// Then check the RUSTUP_TOOLCHAIN environment variable
else if let Some(ref name) = self.env_override {
} _ => { match self.env_override { Some(ref name) => {
// Because path based toolchain files exist, this has to support
// custom, distributable, and absolute path toolchains otherwise
// rustup's export of a RUSTUP_TOOLCHAIN when running a process will
// error when a nested rustup invocation occurs
Some((name.clone().into(), ActiveReason::Environment))
}
// Then walk up the directory tree from 'path' looking for either the
// directory in the override database, or a `rust-toolchain{.toml}` file,
// in that order.
else if let Some((override_cfg, active_reason)) = self.settings_file.with(|s| {
} _ => { match self.settings_file.with(|s| {
self.find_override_from_dir_walk(&self.current_dir, s)
})? {
})? { Some((override_cfg, active_reason)) => {
Some((override_cfg, active_reason))
}
// Otherwise, there is no override.
else {
} _ => {
None
};
}}}}}};

Ok(override_config)
}
Expand Down Expand Up @@ -753,15 +745,15 @@ impl<'a> Cfg<'a> {
force_non_host: bool,
verbose: bool,
) -> Result<(LocalToolchainName, ActiveReason)> {
if let Some((override_config, reason)) = self.find_override_config()? {
match self.find_override_config()? { Some((override_config, reason)) => {
let toolchain = override_config.clone().into_local_toolchain_name();
if let OverrideCfg::Official {
match override_config
{ OverrideCfg::Official {
toolchain,
components,
targets,
profile,
} = override_config
{
} => {
self.ensure_installed(
&toolchain,
components,
Expand All @@ -771,22 +763,22 @@ impl<'a> Cfg<'a> {
verbose,
)
.await?;
} else {
} _ => {
Toolchain::with_reason(self, toolchain.clone(), &reason)?;
}
}}
Ok((toolchain, reason))
} else if let Some(toolchain) = self.get_default()? {
} _ => { match self.get_default()? { Some(toolchain) => {
let reason = ActiveReason::Default;
if let ToolchainName::Official(desc) = &toolchain {
match &toolchain { ToolchainName::Official(desc) => {
self.ensure_installed(desc, vec![], vec![], None, force_non_host, verbose)
.await?;
} else {
} _ => {
Toolchain::with_reason(self, toolchain.clone().into(), &reason)?;
}
}}
Ok((toolchain.into(), reason))
} else {
} _ => {
Err(no_toolchain_error(self.process))
}
}}}}
}

// Returns a Toolchain matching the given ToolchainDesc, installing it and
Expand Down Expand Up @@ -894,11 +886,11 @@ impl<'a> Cfg<'a> {
self.list_toolchains()?
.into_iter()
.filter_map(|t| {
if let ToolchainName::Official(desc) = t {
match t { ToolchainName::Official(desc) => {
Some(desc)
} else {
} _ => {
None
}
}}
})
.filter(ToolchainDesc::is_tracking)
.map(|n| {
Expand Down
78 changes: 37 additions & 41 deletions src/diskio/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ImmediateUnpacker {
fn deque(&self) -> Box<dyn Iterator<Item = CompletedIo>> {
let mut guard = self.incremental_state.lock().unwrap();
// incremental file in progress
if let Some(ref mut state) = *guard {
match *guard { Some(ref mut state) => {
// Case 1: pending errors
if state.finished {
let mut item = state.item.take().unwrap();
Expand All @@ -59,9 +59,9 @@ impl ImmediateUnpacker {
completed_chunks.append(&mut state.completed_chunks);
Box::new(completed_chunks.into_iter().map(CompletedIo::Chunk))
}
} else {
} _ => {
Box::new(None.into_iter())
}
}}
}
}

Expand All @@ -81,21 +81,20 @@ impl Executor for ImmediateUnpacker {
// If there is a pending error, return it, otherwise stash the
// Item for eventual return when the file is finished.
let mut guard = self.incremental_state.lock().unwrap();
if let Some(ref mut state) = *guard {
if state.err.is_some() {
let err = state.err.take().unwrap();
item.result = err;
item.finish = item
.start
.map(|s| Instant::now().saturating_duration_since(s));
*guard = None;
Box::new(Some(CompletedIo::Item(item)).into_iter())
} else {
state.item = Some(item);
Box::new(None.into_iter())
}
let Some(ref mut state) = *guard else {
unreachable!()
};
if state.err.is_some() {
let err = state.err.take().unwrap();
item.result = err;
item.finish = item
.start
.map(|s| Instant::now().saturating_duration_since(s));
*guard = None;
Box::new(Some(CompletedIo::Item(item)).into_iter())
} else {
unreachable!();
state.item = Some(item);
Box::new(None.into_iter())
}
};
}
Expand Down Expand Up @@ -181,47 +180,44 @@ impl IncrementalFileWriter {
if (self.state.lock().unwrap()).is_none() {
return false;
}
let chunk = if let FileBuffer::Immediate(v) = chunk {
v
} else {
let FileBuffer::Immediate(chunk) = chunk else {
unreachable!()
};
match self.write(chunk) {
Ok(v) => v,
Err(e) => {
let mut state = self.state.lock().unwrap();
if let Some(ref mut state) = *state {
match *state { Some(ref mut state) => {
state.err.replace(Err(e));
state.finished = true;
false
} else {
} _ => {
false
}
}}
}
}
}

fn write(&mut self, chunk: Vec<u8>) -> std::result::Result<bool, io::Error> {
let mut state = self.state.lock().unwrap();
if let Some(ref mut state) = *state {
if let Some(ref mut file) = self.file.as_mut() {
// Length 0 vector is used for clean EOF signalling.
if chunk.is_empty() {
trace_scoped!("close", "name:": self.path_display);
drop(std::mem::take(&mut self.file));
state.finished = true;
} else {
trace_scoped!("write_segment", "name": self.path_display, "len": chunk.len());
file.write_all(&chunk)?;

state.completed_chunks.push(chunk.len());
}
Ok(true)
let Some(ref mut state) = *state else {
unreachable!()
};
match self.file.as_mut() { Some(ref mut file) => {
// Length 0 vector is used for clean EOF signalling.
if chunk.is_empty() {
trace_scoped!("close", "name:": self.path_display);
drop(std::mem::take(&mut self.file));
state.finished = true;
} else {
Ok(false)
trace_scoped!("write_segment", "name": self.path_display, "len": chunk.len());
file.write_all(&chunk)?;

state.completed_chunks.push(chunk.len());
}
} else {
unreachable!();
}
Ok(true)
} _ => {
Ok(false)
}}
}
}
71 changes: 35 additions & 36 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ fn filter_result(op: &mut CompletedIo) -> io::Result<()> {
// mkdir of e.g. ~/.rustup already existing is just fine;
// for others it would be better to know whether it is
// expected to exist or not -so put a flag in the state.
if let Kind::Directory = op.kind {
Ok(())
} else {
Err(e)
match op.kind {
Kind::Directory => Ok(()),
_ => Err(e),
}
}
_ => Err(e),
Expand Down Expand Up @@ -454,40 +453,40 @@ fn unpack_without_first_dir<R: Read>(

let item = loop {
// Create the full path to the entry if it does not exist already
if let Some(parent) = item.full_path.to_owned().parent() {
match directories.get_mut(parent) {
None => {
// Tar has item before containing directory
// Complain about this so we can see if these exist.
writeln!(
process.stderr().lock(),
"Unexpected: missing parent '{}' for '{}'",
parent.display(),
entry.path()?.display()
)?;
directories.insert(parent.to_owned(), DirStatus::Pending(vec![item]));
item = Item::make_dir(parent.to_owned(), 0o755);
// Check the parent's parent
continue;
}
Some(DirStatus::Exists) => {
break Some(item);
}
Some(DirStatus::Pending(pending)) => {
// Parent dir is being made
pending.push(item);
if incremental_file_sender.is_none() {
// take next item from tar
continue 'entries;
} else {
// don't submit a new item for processing, but do be ready to feed data to the incremental file.
break None;
}
let full_path = item.full_path.to_owned();
let Some(parent) = full_path.parent() else {
// We should never see a path with no parent.
unreachable!()
};
match directories.get_mut(parent) {
None => {
// Tar has item before containing directory
// Complain about this so we can see if these exist.
writeln!(
process.stderr().lock(),
"Unexpected: missing parent '{}' for '{}'",
parent.display(),
entry.path()?.display()
)?;
directories.insert(parent.to_owned(), DirStatus::Pending(vec![item]));
item = Item::make_dir(parent.to_owned(), 0o755);
// Check the parent's parent
continue;
}
Some(DirStatus::Exists) => {
break Some(item);
}
Some(DirStatus::Pending(pending)) => {
// Parent dir is being made
pending.push(item);
if incremental_file_sender.is_none() {
// take next item from tar
continue 'entries;
} else {
// don't submit a new item for processing, but do be ready to feed data to the incremental file.
break None;
}
}
} else {
// We should never see a path with no parent.
panic!();
}
};

Expand Down
Loading