{"record":{"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":"exception","errorClass":null,"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_run.rs#L69-L105","documentation":"Thrown by `cargo run` when a specific target filter (e.g. `--bin a --bin b` or `--example x --bin y`) selects more than one executable. `cargo run` can execute at most one binary, so multiple explicit selections are rejected even when the filter is specific.","triggerScenarios":"Running `cargo run` with multiple `--bin` flags, or a combination of `--bin` and `--example` flags that together match more than one runnable target. `bins.len() > 1` and `options.filter.is_specific()` is true.","commonSituations":"Passing `--bin foo --bin bar` to `cargo run`; using a filter that accidentally matches both a binary and an example; scripting `cargo run` with programmatically-built filters.","solutions":["Pass only a single `--bin` or `--example` flag to `cargo run`.","If you need to build multiple targets, use `cargo build` instead.","Review the available targets listed in the error message and pick one."],"exampleFix":"# Before — multiple binaries\ncargo run --bin app --bin cli\n\n# After — single binary\ncargo run --bin app","handlingStrategy":"validation","validationCode":"// Validate that only one executable target is selected\nfn count_selected_targets(bins: &[(&cargo::core::Package, &cargo::core::Target)]) -> usize {\n    bins.len()\n}\n// Ensure this is exactly 1 before calling ops::run","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass at most one `--bin` or `--example` flag to `cargo run`.","Review the error's target list and pick exactly one.","Use `cargo build` when you need to compile multiple targets."],"tags":["cargo-run","multiple-targets","target-selection","binary"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}