Skip to content

Commit e797526

Browse files
committed
Code cleanups for the split-host work
1 parent e24bf92 commit e797526

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,11 @@ impl<'cfg> RustcTargetData<'cfg> {
691691
// `--target` flag is not specified. Since the unit_dependency code
692692
// needs access to the target config data, create a copy so that it
693693
// can be found. See `rebuild_unit_graph_shared` for why this is done.
694-
let target_applies_to_host = config.target_applies_to_host();
695-
if target_applies_to_host.is_err() {
696-
return Err(target_applies_to_host.unwrap_err());
697-
}
694+
let target_applies_to_host = config.target_applies_to_host()?;
698695
let host_config = if requested_kinds.iter().any(CompileKind::is_host) {
699696
let ct = CompileTarget::new(&rustc.host)?;
700697
target_info.insert(ct, host_info.clone());
701-
let target_host_config = if target_applies_to_host.unwrap() {
698+
let target_host_config = if target_applies_to_host {
702699
let target_cfg_clone = config.target_cfg_triple(&rustc.host)?;
703700
target_config.insert(ct, target_cfg_clone.clone());
704701
target_cfg_clone
@@ -708,7 +705,7 @@ impl<'cfg> RustcTargetData<'cfg> {
708705
};
709706
target_host_config
710707
} else {
711-
if target_applies_to_host.unwrap() {
708+
if target_applies_to_host {
712709
config.target_cfg_triple(&rustc.host)?
713710
} else {
714711
config.host_cfg_triple(&rustc.host)?

src/cargo/util/config/target.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ
6767
/// Returns true if the `[target]` table should be applied to host targets.
6868
pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
6969
if config.cli_unstable().target_applies_to_host {
70-
let target_applies_to_host = config.get::<bool>("target-applies-to-host");
71-
if target_applies_to_host.is_ok() {
72-
Ok(target_applies_to_host.unwrap())
70+
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
71+
Ok(target_applies_to_host)
7372
} else {
74-
if config.cli_unstable().host_config {
75-
Ok(false)
76-
} else {
77-
Ok(true)
78-
}
73+
Ok(!config.cli_unstable().host_config)
7974
}
8075
} else {
8176
if config.cli_unstable().host_config {
@@ -91,9 +86,10 @@ pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
9186
/// Loads a single `[host]` table for the given triple.
9287
pub(super) fn load_host_triple(config: &Config, triple: &str) -> CargoResult<TargetConfig> {
9388
if config.cli_unstable().host_config {
94-
let host_triple_key = ConfigKey::from_str(&format!("host.{}", triple));
89+
let host_triple_prefix = format!("host.{}", triple);
90+
let host_triple_key = ConfigKey::from_str(&host_triple_prefix);
9591
let host_prefix = match config.get_cv(&host_triple_key)? {
96-
Some(_) => format!("host.{}", triple),
92+
Some(_) => host_triple_prefix,
9793
None => "host".to_string(),
9894
};
9995
load_config_table(config, &host_prefix)

0 commit comments

Comments
 (0)