Skip to content

Commit

Permalink
Auto merge of #9613 - danieleades:refactor/collapse-if-blocks, r=ehuss
Browse files Browse the repository at this point in the history
collapse nested if blocks
  • Loading branch information
bors committed Aug 6, 2021
2 parents 32b1ed1 + c5da878 commit e928b62
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
12 changes: 6 additions & 6 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
self.compilation
.binaries
.push(self.unit_output(unit, bindst));
} else if unit.target.is_cdylib() {
if !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit) {
self.compilation
.cdylibs
.push(self.unit_output(unit, bindst));
}
} else if unit.target.is_cdylib()
&& !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit)
{
self.compilation
.cdylibs
.push(self.unit_output(unit, bindst));
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/cargo/ops/cargo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ pub struct GetOptions<'a> {
}

pub fn get(config: &Config, opts: &GetOptions<'_>) -> CargoResult<()> {
if opts.show_origin {
if !matches!(opts.format, ConfigFormat::Toml) {
bail!(
"the `{}` format does not support --show-origin, try the `toml` format instead",
opts.format
);
}
if opts.show_origin && !matches!(opts.format, ConfigFormat::Toml) {
bail!(
"the `{}` format does not support --show-origin, try the `toml` format instead",
opts.format
);
}
let key = match opts.key {
Some(key) => ConfigKey::from_str(key),
Expand Down
24 changes: 11 additions & 13 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,18 @@ fn install_one(
specify an alternate source",
src.path().display()
);
} else if src.path().join("cargo.toml").exists() {
bail!(
"`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
--path must point to a directory containing a Cargo.toml file.",
src.path().display()
)
} else {
if src.path().join("cargo.toml").exists() {
bail!(
"`{}` does not contain a Cargo.toml file, but found cargo.toml please try to rename it to Cargo.toml. \
--path must point to a directory containing a Cargo.toml file.",
src.path().display()
)
} else {
bail!(
"`{}` does not contain a Cargo.toml file. \
--path must point to a directory containing a Cargo.toml file.",
src.path().display()
)
}
bail!(
"`{}` does not contain a Cargo.toml file. \
--path must point to a directory containing a Cargo.toml file.",
src.path().display()
)
}
}
select_pkg(
Expand Down
16 changes: 7 additions & 9 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,13 @@ impl Summaries {
// present and considered fresh this is where the debug assertions
// actually happens to verify that our cache is indeed fresh and
// computes exactly the same value as before.
if cfg!(debug_assertions) && cache_contents.is_some() {
if cache_bytes != cache_contents {
panic!(
"original cache contents:\n{:?}\n\
does not equal new cache contents:\n{:?}\n",
cache_contents.as_ref().map(|s| String::from_utf8_lossy(s)),
cache_bytes.as_ref().map(|s| String::from_utf8_lossy(s)),
);
}
if cfg!(debug_assertions) && cache_contents.is_some() && cache_bytes != cache_contents {
panic!(
"original cache contents:\n{:?}\n\
does not equal new cache contents:\n{:?}\n",
cache_contents.as_ref().map(|s| String::from_utf8_lossy(s)),
cache_bytes.as_ref().map(|s| String::from_utf8_lossy(s)),
);
}

// Once we have our `cache_bytes` which represents the `Summaries` we're
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/util/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
} else {
Ok(!config.cli_unstable().host_config)
}
} else if config.cli_unstable().host_config {
anyhow::bail!(
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
);
} else {
if config.cli_unstable().host_config {
anyhow::bail!(
"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set"
);
} else {
Ok(true)
}
Ok(true)
}
}

Expand Down

0 comments on commit e928b62

Please sign in to comment.