rust-lang/cargo · error
several matching instances of `target.'cfg(..)'.runner` in c
Error message
several matching instances of `target.'cfg(..)'.runner` in configurations
first match `{}` located in {}
second match `{}` located in {} What it means
In target_runner (compilation.rs:533-552), Cargo selects a `target.'cfg(...)'.runner` by filtering all configured cfg-runner entries whose cfg key matches the current target's cfg. If MORE THAN ONE entry matches, the choice is ambiguous and Cargo bails, printing the first and second matching keys along with the config files (definition locations) that defined them.
Source
Thrown at src/compiler/compilation.rs:543
// With `target-applies-to-host = true`,
// host artifacts must fall through to pick up from [target]
// since this is the stable behavior
if kind.is_host() && !bcx.gctx.target_applies_to_host()? {
return Ok(None);
}
// try target.'cfg(...)'.runner
let target_cfg = bcx.target_data.info(kind).cfg();
let mut cfgs = bcx
.gctx
.target_cfgs()?
.iter()
.filter_map(|(key, cfg)| cfg.runner.as_ref().map(|runner| (key, runner)))
.filter(|(key, _runner)| CfgExpr::matches_key(key, target_cfg));
let matching_runner = cfgs.next();
if let Some((key, runner)) = cfgs.next() {
anyhow::bail!(
"several matching instances of `target.'cfg(..)'.runner` in configurations\n\
first match `{}` located in {}\n\
second match `{}` located in {}",
matching_runner.unwrap().0,
matching_runner.unwrap().1.definition,
key,
runner.definition
);
}
Ok(matching_runner.map(|(_k, runner)| {
(
runner.val.path.clone().resolve_program(bcx.gctx),
runner.val.args.clone(),
)
}))
}
/// Gets the user-specified linker for a particular host or target from the configuration.View on GitHub (pinned to 0e07a15537)
Solutions
- Disambiguate by keeping only ONE matching cfg-runner entry; remove or narrow the broader cfg expression.
- Use the most specific key (e.g. an exact triple `[target.x86_64-unknown-linux-gnu].runner`) instead of overlapping cfgs.
- Audit layered config files (`~/.cargo/config.toml`, `.cargo/config.toml`, `--config` flags) for duplicate runner definitions.
- If two different runners are legitimately needed, differentiate their cfg conditions so they never both match.
Example fix
// before (.cargo/config.toml) [target.'cfg(unix)'.runner] runner = "qemu-unix" [target.'cfg(linux)'.runner] runner = "qemu-linux" // both match a linux build -> error // after [target.'cfg(target_os = "macos")'.runner] runner = "qemu-macos" [target.'cfg(target_os = "linux")'.runner] runner = "qemu-linux"
Defensive patterns
Strategy: validation
Validate before calling
// Detect overlapping cfg-runner keys for a given target cfg
let matching: Vec<_> = target_cfgs.iter()
.filter(|(_, c)| c.runner.is_some())
.filter(|(k, _)| CfgExpr::matches_key(k, &target_cfg))
.collect();
if matching.len() > 1 {
return Err(format!("{} target.'cfg(..)'.runner match; disambiguate", matching.len()));
} Type guard
fn single_runner_match(entries: &[(&str, &Config)]) -> bool {
entries.iter().filter(|(_, c)| c.runner.is_some()).count() <= 1
}
Prevention
- Audit layered cargo config files for runner duplicates.
- Prefer exact-triple runner keys over broad cfg expressions.
- Lint config in CI for overlapping cfg keys.
When it happens
Trigger: Defining multiple `[target.'cfg(...)'.runner]` entries in `.cargo/config.toml` (or across layered config files) whose cfg expressions both match the build target — e.g. `[target.'cfg(unix)'.runner]` and `[target.'cfg(linux)'.runner]` both matching a Linux target.
Common situations: Overlapping cfg-based runner config across global and project config files; broadening a cfg expression that now collides with a more specific one; merging config from multiple team members; `[target.<triple>.runner]` plus a matching `[target.'cfg(...)'.runner]`.
Related errors
- several matching instances of `target.'cfg(..)'.linker` in c
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
- subcommand is required, but `{alias_name}` is empty
- dependency `{}` in package `{}` requires a `{}` artifact to
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/6580d0bae007aeb3.json.
Report an issue: GitHub.