{"record":{"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":"exception","errorClass":"anyhow::Error","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 tuple.\npub(super) fn load_host_triple(gctx: &GlobalContext, triple: &str) -> CargoResult<TargetConfig> {\n    if gctx.cli_unstable().host_config {\n        let host_triple_prefix = [\"host\", triple];\n        let host_triple_key = ConfigKey::from_parts(host_triple_prefix);\n        let host_prefix = match gctx.get_cv(&host_triple_key)? {\n            Some(_) => host_triple_prefix.as_slice(),\n            None => &[\"host\"],\n        };\n        load_config_table(gctx, host_prefix)\n    } else {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/context/target.rs#L73-L109","documentation":"Thrown by get_target_applies_to_host() when the -Z host-config unstable flag is enabled but -Z target-applies-to-host is not. These nightly-only flags are interdependent: host-config allows defining per-host-target configuration, but target-applies-to-host must be set to control whether [target] tables apply to host targets.","triggerScenarios":"Running cargo with -Z host-config without also passing -Z target-applies-to-host.","commonSituations":"Configuring cross-compilation host-specific overrides without enabling the prerequisite flag. Following partial documentation or examples that only mention host-config.","solutions":["Add -Z target-applies-to-host to the cargo invocation alongside -Z host-config","Set target-applies-to-host in config.toml under the unstable table if using config-based activation"],"exampleFix":"# before\ncargo build -Z host-config\n\n# after\ncargo build -Z host-config -Z target-applies-to-host","handlingStrategy":"validation","validationCode":"// Validate unstable flag combinations before invoking cargo\nfn validate_unstable_flags(flags: &[String]) -> Result<(), String> {\n    let has_host_config = flags.iter().any(|f| f == \"host-config\");\n    let has_target_applies = flags.iter().any(|f| f == \"target-applies-to-host\");\n    if has_host_config && !has_target_applies {\n        return Err(\"-Z host-config requires -Z target-applies-to-host\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use -Z host-config and -Z target-applies-to-host together","Review unstable flag documentation for interdependencies before enabling them","Pin the nightly toolchain version when relying on unstable flags"],"tags":["configuration","unstable-flags","target","cross-compilation"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}