Skip to content

Commit f63f82b

Browse files
committed
chore: fix new clippy warnings
1 parent 2c70689 commit f63f82b

File tree

9 files changed

+135
-141
lines changed

9 files changed

+135
-141
lines changed

src/cli/rustup_mode.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ fn handle_epipe(res: Result<utils::ExitCode>) -> Result<utils::ExitCode> {
4949
match res {
5050
Err(e) => {
5151
let root = e.root_cause();
52-
if let Some(io_err) = root.downcast_ref::<std::io::Error>() {
53-
if io_err.kind() == std::io::ErrorKind::BrokenPipe {
54-
return Ok(utils::ExitCode(0));
55-
}
52+
if let Some(io_err) = root.downcast_ref::<std::io::Error>()
53+
&& io_err.kind() == std::io::ErrorKind::BrokenPipe
54+
{
55+
return Ok(utils::ExitCode(0));
5656
}
5757
Err(e)
5858
}
@@ -774,10 +774,10 @@ async fn default_(
774774
}
775775
};
776776

777-
if let Some((toolchain, reason)) = cfg.active_toolchain()? {
778-
if !matches!(reason, ActiveReason::Default) {
779-
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
780-
}
777+
if let Some((toolchain, reason)) = cfg.active_toolchain()?
778+
&& !matches!(reason, ActiveReason::Default)
779+
{
780+
info!("note that the toolchain '{toolchain}' is currently in use ({reason})");
781781
}
782782
} else {
783783
let default_toolchain = cfg
@@ -1631,8 +1631,8 @@ async fn doc(
16311631
) -> Result<utils::ExitCode> {
16321632
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
16331633

1634-
if let Ok(distributable) = DistributableToolchain::try_from(&toolchain) {
1635-
if let [_] = distributable
1634+
if let Ok(distributable) = DistributableToolchain::try_from(&toolchain)
1635+
&& let [_] = distributable
16361636
.components()?
16371637
.into_iter()
16381638
.filter(|cstatus| {
@@ -1641,19 +1641,18 @@ async fn doc(
16411641
.take(1)
16421642
.collect::<Vec<ComponentStatus>>()
16431643
.as_slice()
1644-
{
1645-
info!(
1646-
"`rust-docs` not installed in toolchain `{}`",
1647-
distributable.desc()
1648-
);
1649-
info!(
1650-
"To install, try `rustup component add --toolchain {} rust-docs`",
1651-
distributable.desc()
1652-
);
1653-
return Err(anyhow!(
1654-
"unable to view documentation which is not installed"
1655-
));
1656-
}
1644+
{
1645+
info!(
1646+
"`rust-docs` not installed in toolchain `{}`",
1647+
distributable.desc()
1648+
);
1649+
info!(
1650+
"To install, try `rustup component add --toolchain {} rust-docs`",
1651+
distributable.desc()
1652+
);
1653+
return Err(anyhow!(
1654+
"unable to view documentation which is not installed"
1655+
));
16571656
};
16581657

16591658
let (doc_path, fragment) = match (topic, doc_page.name()) {

src/config.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -659,17 +659,15 @@ impl<'a> Cfg<'a> {
659659
let default_host_triple = get_default_host_triple(settings, self.process);
660660
// Do not permit architecture/os selection in channels as
661661
// these are host specific and toolchain files are portable.
662-
if let ResolvableToolchainName::Official(ref name) = toolchain_name {
663-
if name.has_triple() {
664-
// Permit fully qualified names IFF the toolchain is installed. TODO(robertc): consider
665-
// disabling this and backing out https://github.com/rust-lang/rustup/pull/2141 (but provide
666-
// the base name in the error to help users)
667-
let resolved_name = &ToolchainName::try_from(toolchain_name_str)?;
668-
if !self.list_toolchains()?.iter().any(|s| s == resolved_name) {
669-
return Err(anyhow!(format!(
670-
"target triple in channel name '{name}'"
671-
)));
672-
}
662+
if let ResolvableToolchainName::Official(ref name) = toolchain_name
663+
&& name.has_triple()
664+
{
665+
// Permit fully qualified names IFF the toolchain is installed. TODO(robertc): consider
666+
// disabling this and backing out https://github.com/rust-lang/rustup/pull/2141 (but provide
667+
// the base name in the error to help users)
668+
let resolved_name = &ToolchainName::try_from(toolchain_name_str)?;
669+
if !self.list_toolchains()?.iter().any(|s| s == resolved_name) {
670+
return Err(anyhow!(format!("target triple in channel name '{name}'")));
673671
}
674672
}
675673

src/dist/component/components.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ impl Components {
3030
let c = Self { prefix };
3131

3232
// Validate that the metadata uses a format we know
33-
if let Some(v) = c.read_version()? {
34-
if v != INSTALLER_VERSION {
35-
bail!(
36-
"unsupported metadata version in existing installation: {}",
37-
v
38-
);
39-
}
33+
if let Some(v) = c.read_version()?
34+
&& v != INSTALLER_VERSION
35+
{
36+
bail!(
37+
"unsupported metadata version in existing installation: {}",
38+
v
39+
);
4040
}
4141

4242
Ok(c)

src/dist/component/package.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,26 @@ fn trigger_children(
254254
op: CompletedIo,
255255
) -> Result<usize> {
256256
let mut result = 0;
257-
if let CompletedIo::Item(item) = op {
258-
if let Kind::Directory = item.kind {
259-
let mut pending = Vec::new();
260-
directories
261-
.entry(item.full_path)
262-
.and_modify(|status| match status {
263-
DirStatus::Exists => unreachable!(),
264-
DirStatus::Pending(pending_inner) => {
265-
pending.append(pending_inner);
266-
*status = DirStatus::Exists;
267-
}
268-
})
269-
.or_insert_with(|| unreachable!());
270-
result += pending.len();
271-
for pending_item in pending.into_iter() {
272-
for mut item in io_executor.execute(pending_item).collect::<Vec<_>>() {
273-
// TODO capture metrics
274-
filter_result(&mut item)?;
275-
result += trigger_children(io_executor, directories, item)?;
257+
if let CompletedIo::Item(item) = op
258+
&& let Kind::Directory = item.kind
259+
{
260+
let mut pending = Vec::new();
261+
directories
262+
.entry(item.full_path)
263+
.and_modify(|status| match status {
264+
DirStatus::Exists => unreachable!(),
265+
DirStatus::Pending(pending_inner) => {
266+
pending.append(pending_inner);
267+
*status = DirStatus::Exists;
276268
}
269+
})
270+
.or_insert_with(|| unreachable!());
271+
result += pending.len();
272+
for pending_item in pending.into_iter() {
273+
for mut item in io_executor.execute(pending_item).collect::<Vec<_>>() {
274+
// TODO capture metrics
275+
filter_result(&mut item)?;
276+
result += trigger_children(io_executor, directories, item)?;
277277
}
278278
}
279279
};
@@ -363,24 +363,24 @@ fn unpack_without_first_dir<R: Read>(
363363
trigger_children(&*io_executor, directories, op)?;
364364
}
365365
// Maybe stream a file incrementally
366-
if let Some(sender) = sender_entry.as_mut() {
367-
if io_executor.buffer_available(IO_CHUNK_SIZE) {
368-
let mut buffer = io_executor.get_buffer(IO_CHUNK_SIZE);
369-
let len = sender
370-
.entry
371-
.by_ref()
372-
.take(IO_CHUNK_SIZE as u64)
373-
.read_to_end(&mut buffer)?;
374-
buffer = buffer.finished();
375-
if len == 0 {
376-
result = true;
377-
}
378-
if !(sender.sender)(buffer) {
379-
bail!(format!(
380-
"IO receiver for '{}' disconnected",
381-
full_path.as_ref().display()
382-
))
383-
}
366+
if let Some(sender) = sender_entry.as_mut()
367+
&& io_executor.buffer_available(IO_CHUNK_SIZE)
368+
{
369+
let mut buffer = io_executor.get_buffer(IO_CHUNK_SIZE);
370+
let len = sender
371+
.entry
372+
.by_ref()
373+
.take(IO_CHUNK_SIZE as u64)
374+
.read_to_end(&mut buffer)?;
375+
buffer = buffer.finished();
376+
if len == 0 {
377+
result = true;
378+
}
379+
if !(sender.sender)(buffer) {
380+
bail!(format!(
381+
"IO receiver for '{}' disconnected",
382+
full_path.as_ref().display()
383+
))
384384
}
385385
}
386386
Ok(result)

src/dist/mod.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ impl FromStr for PartialVersion {
229229
// `semver::Comparator::from_str` supports an optional operator
230230
// (e.g. `=`, `>`, `>=`, `<`, `<=`, `~`, `^`, `*`) before the
231231
// partial version, so we should exclude that case first.
232-
if let Some(ch) = ver.chars().nth(0) {
233-
if !ch.is_ascii_digit() {
234-
return Err(anyhow!(
235-
"expected ASCII digit at the beginning of `{ver}`, found `{ch}`"
236-
)
237-
.context("error parsing `PartialVersion`"));
238-
}
232+
if let Some(ch) = ver.chars().nth(0)
233+
&& !ch.is_ascii_digit()
234+
{
235+
return Err(
236+
anyhow!("expected ASCII digit at the beginning of `{ver}`, found `{ch}`")
237+
.context("error parsing `PartialVersion`"),
238+
);
239239
}
240240
let (ver, pre) = ver.split_once('-').unwrap_or((ver, ""));
241241
let comparator =
@@ -1017,12 +1017,12 @@ pub(crate) async fn update_from_dist(
10171017
}
10181018
};
10191019

1020-
if let Some(backtrack_limit) = backtrack_limit {
1021-
if backtrack_limit < 1 {
1022-
// This unwrap is safe because we can only hit this if we've
1023-
// had a chance to set first_err
1024-
break Err(first_err.unwrap());
1025-
}
1020+
if let Some(backtrack_limit) = backtrack_limit
1021+
&& backtrack_limit < 1
1022+
{
1023+
// This unwrap is safe because we can only hit this if we've
1024+
// had a chance to set first_err
1025+
break Err(first_err.unwrap());
10261026
}
10271027

10281028
// The user asked to update their nightly, but the latest nightly does not have all
@@ -1118,10 +1118,9 @@ async fn try_update_from_dist_(
11181118
.components
11191119
.iter()
11201120
.find(|c| c.short_name_in_manifest() == component.short_name_in_manifest())
1121+
&& c.target.is_none()
11211122
{
1122-
if c.target.is_none() {
1123-
component = component.wildcard();
1124-
}
1123+
component = component.wildcard();
11251124
}
11261125
all_components.insert(component);
11271126
}
@@ -1215,12 +1214,12 @@ async fn try_update_from_dist_(
12151214
.await;
12161215

12171216
// inspect, determine what context to add, then process afterwards.
1218-
if let Err(e) = &result {
1219-
if let Some(RustupError::DownloadNotExists { .. }) = e.downcast_ref::<RustupError>() {
1220-
return result.with_context(|| {
1221-
format!("could not download nonexistent rust version `{toolchain_str}`")
1222-
});
1223-
}
1217+
if let Err(e) = &result
1218+
&& let Some(RustupError::DownloadNotExists { .. }) = e.downcast_ref::<RustupError>()
1219+
{
1220+
return result.with_context(|| {
1221+
format!("could not download nonexistent rust version `{toolchain_str}`")
1222+
});
12241223
}
12251224

12261225
result

src/download/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ async fn download_file_(
100100
// This callback will write the download to disk and optionally
101101
// hash the contents, then forward the notification up the stack
102102
let callback: &dyn Fn(Event<'_>) -> anyhow::Result<()> = &|msg| {
103-
if let Event::DownloadDataReceived(data) = msg {
104-
if let Some(h) = hasher.borrow_mut().as_mut() {
105-
h.update(data);
106-
}
103+
if let Event::DownloadDataReceived(data) = msg
104+
&& let Some(h) = hasher.borrow_mut().as_mut()
105+
{
106+
h.update(data);
107107
}
108108

109109
match msg {
@@ -469,18 +469,17 @@ mod curl {
469469
// Listen for headers and parse out a `Content-Length` (case-insensitive) if it
470470
// comes so we know how much we're downloading.
471471
transfer.header_function(|header| {
472-
if let Ok(data) = str::from_utf8(header) {
473-
let prefix = "content-length: ";
474-
if data.to_ascii_lowercase().starts_with(prefix) {
475-
if let Ok(s) = data[prefix.len()..].trim().parse::<u64>() {
476-
let msg = Event::DownloadContentLengthReceived(s + resume_from);
477-
match callback(msg) {
478-
Ok(()) => (),
479-
Err(e) => {
480-
*cberr.borrow_mut() = Some(e);
481-
return false;
482-
}
483-
}
472+
let prefix = "content-length: ";
473+
if let Ok(data) = str::from_utf8(header)
474+
&& data.to_ascii_lowercase().starts_with(prefix)
475+
&& let Ok(s) = data[prefix.len()..].trim().parse::<u64>()
476+
{
477+
let msg = Event::DownloadContentLengthReceived(s + resume_from);
478+
match callback(msg) {
479+
Ok(()) => (),
480+
Err(e) => {
481+
*cberr.borrow_mut() = Some(e);
482+
return false;
484483
}
485484
}
486485
}

src/env_var.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ pub(crate) fn insert_path(
2727
prepend.into()
2828
};
2929

30-
if let Some(path) = append {
31-
if !parts.contains(&path) {
32-
parts.push_back(path);
33-
}
30+
if let Some(path) = append
31+
&& !parts.contains(&path)
32+
{
33+
parts.push_back(path);
3434
}
3535

3636
if let Ok(new_value) = env::join_paths(parts) {

src/toolchain.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,15 @@ impl<'a> Toolchain<'a> {
345345
);
346346
return Ok(cmd);
347347
}
348-
} else if let "rust-analyzer" | "rust-analyzer.exe" = binary {
349-
if let Some(cmd) = self.maybe_do_rust_analyzer_fallback(binary)? {
350-
info!("`rust-analyzer` is unavailable for the active toolchain");
351-
info!(
352-
r#"falling back to "{}""#,
353-
Path::new(cmd.get_program()).display()
354-
);
355-
return Ok(cmd);
356-
}
348+
} else if let "rust-analyzer" | "rust-analyzer.exe" = binary
349+
&& let Some(cmd) = self.maybe_do_rust_analyzer_fallback(binary)?
350+
{
351+
info!("`rust-analyzer` is unavailable for the active toolchain");
352+
info!(
353+
r#"falling back to "{}""#,
354+
Path::new(cmd.get_program()).display()
355+
);
356+
return Ok(cmd);
357357
}
358358

359359
self.create_command(binary)
@@ -490,12 +490,12 @@ impl<'a> Toolchain<'a> {
490490
// but only if we know the absolute path to cargo.
491491
// This works around an issue with old versions of cargo not updating
492492
// the environment variable itself.
493-
if Path::new(&binary).file_stem() == Some("cargo".as_ref()) && path.is_absolute() {
494-
if let Some(cargo) = self.cfg.process.var_os("CARGO") {
495-
if fs::read_link(&cargo).is_ok_and(|p| p.file_stem() == Some("rustup".as_ref())) {
496-
cmd.env("CARGO", path);
497-
}
498-
}
493+
if Path::new(&binary).file_stem() == Some("cargo".as_ref())
494+
&& path.is_absolute()
495+
&& let Some(cargo) = self.cfg.process.var_os("CARGO")
496+
&& fs::read_link(&cargo).is_ok_and(|p| p.file_stem() == Some("rustup".as_ref()))
497+
{
498+
cmd.env("CARGO", path);
499499
}
500500
Ok(cmd)
501501
}

0 commit comments

Comments
 (0)