Skip to content

Commit e928b62

Browse files
committed
Auto merge of #9613 - danieleades:refactor/collapse-if-blocks, r=ehuss
collapse nested if blocks
2 parents 32b1ed1 + c5da878 commit e928b62

File tree

5 files changed

+34
-42
lines changed

5 files changed

+34
-42
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
195195
self.compilation
196196
.binaries
197197
.push(self.unit_output(unit, bindst));
198-
} else if unit.target.is_cdylib() {
199-
if !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit) {
200-
self.compilation
201-
.cdylibs
202-
.push(self.unit_output(unit, bindst));
203-
}
198+
} else if unit.target.is_cdylib()
199+
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
200+
{
201+
self.compilation
202+
.cdylibs
203+
.push(self.unit_output(unit, bindst));
204204
}
205205
}
206206

src/cargo/ops/cargo_config.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ pub struct GetOptions<'a> {
5151
}
5252

5353
pub fn get(config: &Config, opts: &GetOptions<'_>) -> CargoResult<()> {
54-
if opts.show_origin {
55-
if !matches!(opts.format, ConfigFormat::Toml) {
56-
bail!(
57-
"the `{}` format does not support --show-origin, try the `toml` format instead",
58-
opts.format
59-
);
60-
}
54+
if opts.show_origin && !matches!(opts.format, ConfigFormat::Toml) {
55+
bail!(
56+
"the `{}` format does not support --show-origin, try the `toml` format instead",
57+
opts.format
58+
);
6159
}
6260
let key = match opts.key {
6361
Some(key) => ConfigKey::from_str(key),

src/cargo/ops/cargo_install.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,18 @@ fn install_one(
211211
specify an alternate source",
212212
src.path().display()
213213
);
214+
} else if src.path().join("cargo.toml").exists() {
215+
bail!(
216+
"`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
217+
--path must point to a directory containing a Cargo.toml file.",
218+
src.path().display()
219+
)
214220
} else {
215-
if src.path().join("cargo.toml").exists() {
216-
bail!(
217-
"`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
218-
--path must point to a directory containing a Cargo.toml file.",
219-
src.path().display()
220-
)
221-
} else {
222-
bail!(
223-
"`{}` does not contain a Cargo.toml file. \
224-
--path must point to a directory containing a Cargo.toml file.",
225-
src.path().display()
226-
)
227-
}
221+
bail!(
222+
"`{}` does not contain a Cargo.toml file. \
223+
--path must point to a directory containing a Cargo.toml file.",
224+
src.path().display()
225+
)
228226
}
229227
}
230228
select_pkg(

src/cargo/sources/registry/index.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,13 @@ impl Summaries {
602602
// present and considered fresh this is where the debug assertions
603603
// actually happens to verify that our cache is indeed fresh and
604604
// computes exactly the same value as before.
605-
if cfg!(debug_assertions) && cache_contents.is_some() {
606-
if cache_bytes != cache_contents {
607-
panic!(
608-
"original cache contents:\n{:?}\n\
609-
does not equal new cache contents:\n{:?}\n",
610-
cache_contents.as_ref().map(|s| String::from_utf8_lossy(s)),
611-
cache_bytes.as_ref().map(|s| String::from_utf8_lossy(s)),
612-
);
613-
}
605+
if cfg!(debug_assertions) && cache_contents.is_some() && cache_bytes != cache_contents {
606+
panic!(
607+
"original cache contents:\n{:?}\n\
608+
does not equal new cache contents:\n{:?}\n",
609+
cache_contents.as_ref().map(|s| String::from_utf8_lossy(s)),
610+
cache_bytes.as_ref().map(|s| String::from_utf8_lossy(s)),
611+
);
614612
}
615613

616614
// Once we have our `cache_bytes` which represents the `Summaries` we're

src/cargo/util/config/target.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
7272
} else {
7373
Ok(!config.cli_unstable().host_config)
7474
}
75+
} else if config.cli_unstable().host_config {
76+
anyhow::bail!(
77+
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
78+
);
7579
} else {
76-
if config.cli_unstable().host_config {
77-
anyhow::bail!(
78-
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
79-
);
80-
} else {
81-
Ok(true)
82-
}
80+
Ok(true)
8381
}
8482
}
8583

0 commit comments

Comments
 (0)