{"id":"a356f02b04838aef","repo":"rust-lang/cargo","slug":"the-zhost-config-flag-requires-the-ztarget-appli","errorCode":null,"errorMessage":"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set","messagePattern":"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/target.rs","lineNumber":91,"sourceCode":"                    other_key, key\n                ))?;\n            }\n            result.push((key, cfg));\n        }\n    }\n    Ok(result)\n}\n\n/// Returns true if the `[target]` table should be applied to host targets.\npub(super) fn get_target_applies_to_host(gctx: &GlobalContext) -> CargoResult<bool> {\n    if gctx.cli_unstable().target_applies_to_host {\n        if let Ok(target_applies_to_host) = gctx.get::<bool>(\"target-applies-to-host\") {\n            Ok(target_applies_to_host)\n        } else {\n            Ok(!gctx.cli_unstable().host_config)\n        }\n    } else if gctx.cli_unstable().host_config {\n        anyhow::bail!(\n            \"the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set\"\n        );\n    } else {\n        Ok(true)\n    }\n}\n\n/// Loads a single `[host]` table for the given triple.\npub(super) fn load_host_triple(gctx: &GlobalContext, triple: &str) -> CargoResult<TargetConfig> {\n    if gctx.cli_unstable().host_config {\n        let host_triple_prefix = format!(\"host.{}\", triple);\n        let host_triple_key = ConfigKey::from_str(&host_triple_prefix);\n        let host_prefix = match gctx.get_cv(&host_triple_key)? {\n            Some(_) => host_triple_prefix,\n            None => \"host\".to_string(),\n        };\n        load_config_table(gctx, &host_prefix)\n    } else {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/target.rs#L73-L109","documentation":"get_target_applies_to_host (target.rs:83-97) gates the `-Zhost-config` feature: it may only be used together with `-Ztarget-applies-to-host`. If host_config is enabled but target_applies_to_host is not (and the `target-applies-to-host` config key is unset), Cargo bails 'the -Zhost-config flag requires the -Ztarget-applies-to-host flag to be set'. The two flags jointly decide whether `[host]` config tables also apply to host targets.","triggerScenarios":"Invoking cargo with `-Zhost-config` but without `-Ztarget-applies-to-host` on the CLI, and with no `target-applies-to-host` config value set.","commonSituations":"Experimenting with the host-config nightly feature and forgetting the companion flag; following a partial example; config that sets `[host.*]` without enabling target-applies-to-host.","solutions":["Pass both flags: `cargo +nightly build -Zhost-config -Ztarget-applies-to-host`.","Alternatively set `target-applies-to-host = true|false` in config.toml so the second unstable flag is implied.","Drop `-Zhost-config` if you do not need `[host]` tables."],"exampleFix":"# before\ncargo +nightly build -Zhost-config\n# after\ncargo +nightly build -Zhost-config -Ztarget-applies-to-host","handlingStrategy":"validation","validationCode":"# Require the companion flag whenever -Zhost-config is used:\nif printf '%s\\n' \"$@\" | grep -q -- '-Zhost-config'; then\n  set -- \"$@\" -Ztarget-applies-to-host\nfi\ncargo +nightly \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair -Zhost-config with -Ztarget-applies-to-host.","Set target-applies-to-host in config.toml to make the intent explicit.","Pin nightly in rust-toolchain.toml for projects using these unstable flags."],"tags":["unstable","nightly","host-config","target","config"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}