{"record":{"id":"6580d0bae007aeb3","repo":"rust-lang/cargo","slug":"several-matching-instances-of-target-cfg-ru","errorCode":null,"errorMessage":"several matching instances of `target.'cfg(..)'.runner` in configurations\nfirst match `{}` located in {}\nsecond match `{}` located in {}","messagePattern":"several matching instances of `target\\.'cfg\\(\\.\\.\\)'\\.runner` in configurations\nfirst match `(.+?)` located in (.+?)\nsecond match `(.+?)` located in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/compilation.rs","lineNumber":543,"sourceCode":"\n    // With `target-applies-to-host = true`,\n    // host artifacts must fall through to pick up from [target]\n    // since this is the stable behavior\n    if kind.is_host() && !bcx.gctx.target_applies_to_host()? {\n        return Ok(None);\n    }\n\n    // try target.'cfg(...)'.runner\n    let target_cfg = bcx.target_data.info(kind).cfg();\n    let mut cfgs = bcx\n        .gctx\n        .target_cfgs()?\n        .iter()\n        .filter_map(|(key, cfg)| cfg.runner.as_ref().map(|runner| (key, runner)))\n        .filter(|(key, _runner)| CfgExpr::matches_key(key, target_cfg));\n    let matching_runner = cfgs.next();\n    if let Some((key, runner)) = cfgs.next() {\n        anyhow::bail!(\n            \"several matching instances of `target.'cfg(..)'.runner` in configurations\\n\\\n             first match `{}` located in {}\\n\\\n             second match `{}` located in {}\",\n            matching_runner.unwrap().0,\n            matching_runner.unwrap().1.definition,\n            key,\n            runner.definition\n        );\n    }\n    Ok(matching_runner.map(|(_k, runner)| {\n        (\n            runner.val.path.clone().resolve_program(bcx.gctx),\n            runner.val.args.clone(),\n        )\n    }))\n}\n\n/// Gets the user-specified linker for a particular host or target from the configuration.","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/src/compiler/compilation.rs#L525-L561","documentation":"Multiple `[target.'cfg(...)'.runner]` entries in configuration match the current target's cfg set, making the runner ambiguous. `CfgExpr::matches_key` returned true for two or more keys, so Cargo cannot pick one deterministically.","triggerScenarios":"Defining overlapping `target.'cfg(target_os = \"linux\")'.runner` and `target.'cfg(unix)'.runner` where both match; importing layered configs (user + project + env) that each set a runner for matching cfgs.","commonSituations":"Workspace merges inheriting multiple config sources; CI adding `CARGO_TARGET_*_RUNNER` alongside a config file runner; evolving cfg expressions to overlap accidentally.","solutions":["Consolidate runner config into a single source (e.g. only `.cargo/config.toml` or only env vars).","Make cfg keys mutually exclusive (e.g. `cfg(all(target_os = \"linux\", not(target_env = \"musl\")))`).","Delete the lower-priority matching entry identified in the error's `first match`/`second match` lines.","Use a single wildcard `target.<triple>.runner` (exact triple) instead of cfg-based matching."],"exampleFix":"// before (.cargo/config.toml)\n[target.'cfg(unix)'.runner]\nrunner = \"qemu-x86_64\"\n[target.'cfg(target_os = \"linux\")'.runner]\nrunner = \"./run.sh\"\n\n// after\n[target.x86_64-unknown-linux-gnu.runner]\nrunner = \"./run.sh\"","handlingStrategy":"validation","validationCode":"fn count_matching_runner_cfgs(target_cfg: &[String], cfgs: &[(String, Runner)]) -> usize {\n    cfgs.iter().filter(|(k, _)| cfg_matches(k, target_cfg)).count()\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Prefer exact-triple runner keys (`target.<triple>.runner`) over cfg-based ones.","Use `cargo config get target` to inspect merged runner entries.","Document which config layer owns the runner in team repos."],"tags":["cargo","config","runner","target-cfg","ambiguous"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}