{"id":"12d13371fd171c95","repo":"rust-lang/cargo","slug":"cargo-run-can-run-at-most-one-executable-but-mu","errorCode":null,"errorMessage":"`cargo run` can run at most one executable, but multiple were specified","messagePattern":"`cargo run` can run at most one executable, but multiple were specified","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_run.rs","lineNumber":87,"sourceCode":"                 or the `default-run` manifest key.\\n\\\n                 available binaries: {}\",\n                names.join(\", \")\n            )\n        } else {\n            let mut message = \"`cargo run` can run at most one executable, but \\\n                 multiple were specified\"\n                .to_owned();\n            write!(&mut message, \"\\nhelp: available targets:\")?;\n            for (pkg, bin) in &bins {\n                write!(\n                    &mut message,\n                    \"\\n    {} `{}` in package `{}`\",\n                    bin.kind().description(),\n                    bin.name(),\n                    pkg.name()\n                )?;\n            }\n            anyhow::bail!(message)\n        }\n    }\n\n    // `cargo run` is only compatible with one `--target` flag at most\n    options.build_config.single_requested_kind()?;\n\n    let compile = ops::compile(ws, options)?;\n    assert_eq!(compile.binaries.len(), 1);\n    let UnitOutput {\n        unit,\n        path,\n        script_metas,\n        env: _env,\n    } = &compile.binaries[0];\n    let exe = match path.strip_prefix(gctx.cwd()) {\n        Ok(path) if path.file_name() == Some(path.as_os_str()) => Path::new(\".\").join(path),\n        Ok(path) => path.to_path_buf(),\n        Err(_) => path.to_path_buf(),","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_run.rs#L69-L105","documentation":"`cargo run` can execute at most one executable. If the target filter resolves to multiple runnable targets while being specific (e.g. several --bin flags, or a combination that yields >1), cargo_run.rs:87 bails and lists the matched targets.","triggerScenarios":"`cargo run --bin a --bin b`, or combining flags such that more than one executable is selected.","commonSituations":"Assuming `cargo run` launches multiple binaries like `cargo build`; copy-pasting multiple --bin flags.","solutions":["Pass exactly one target: `cargo run --bin a`.","Run each binary in a separate `cargo run` invocation.","If you scripted this, loop over the binaries calling `cargo run --bin $b` once each."],"exampleFix":"# before\n$ cargo run --bin a --bin b\nerror: `cargo run` can run at most one executable, but multiple were specified\n\n# after\n$ cargo run --bin a\n$ cargo run --bin b","handlingStrategy":"validation","validationCode":"# Allow at most one runnable target on `cargo run`:\nn=$(printf '%s\\n' \"$@\" | grep -c -- '--bin\\|--example')\nif [ \"$n\" -gt 1 ]; then\n  echo \"cargo run accepts at most one executable\" >&2; exit 1\nfi\ncargo run \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a single --bin (or --example) to `cargo run`.","Loop over binaries in a script, one `cargo run` each.","Don't assume `cargo run` mirrors `cargo build` multi-target behavior."],"tags":["run","targets","binary"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}