{"record":{"id":"8b19fb6cd26ed05b","repo":"rust-lang/rust","slug":"multiple-compilation-artifacts-are-not-supported","errorCode":null,"errorMessage":"Multiple compilation artifacts are not supported.","messagePattern":"Multiple compilation artifacts are not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/tools/rust-analyzer/editors/code/src/toolchain.ts","lineNumber":118,"sourceCode":"            );\n        } catch (err) {\n            log.error(`Cargo invocation has failed: ${err}`);\n            throw new Error(`Cargo invocation has failed: ${err}`, { cause: err });\n        }\n\n        return spec.filter?.(artifacts) ?? artifacts;\n    }\n\n    async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {\n        const artifacts = await this.getArtifacts(\n            Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),\n            runnableArgs.environment,\n        );\n\n        if (artifacts.length === 0) {\n            throw new Error(\"No compilation artifacts\");\n        } else if (artifacts.length > 1) {\n            throw new Error(\"Multiple compilation artifacts are not supported.\");\n        }\n\n        const artifact = unwrapUndefinable(artifacts[0]);\n        return artifact.fileName;\n    }\n\n    private async runCargo(\n        cargoArgs: string[],\n        onStdoutJson: (obj: CompilerMessage) => void,\n        onStderrString: (data: string) => void,\n        env?: Record<string, string>,\n    ): Promise<number> {\n        const path = await cargoPath(env);\n        return await new Promise((resolve, reject) => {\n            const cargo = cp.spawn(path, cargoArgs, {\n                stdio: [\"ignore\", \"pipe\", \"pipe\"],\n                cwd: this.rootFolder,\n                env: this.env,","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/editors/code/src/toolchain.ts#L100-L136","documentation":"Thrown by Cargo.executableFromArgs() at toolchain.ts:117-118 when getArtifacts() returns more than one CompilationArtifact. executableFromArgs() expects exactly one executable to run/debug; when multiple match (e.g. both a binary and a test binary, or multiple binaries from the same build), it cannot decide which to launch and aborts.","triggerScenarios":"getArtifacts() returns an array with length > 1 at toolchain.ts:117. This happens when: a 'run'/'build' spec is used on a crate with multiple [[bin]] targets that all match, the filter (line 64) doesn't narrow sufficiently (e.g. a non-test/non-bench build produces both a bin and a custom-build artifact that slips through), or cargo emits multiple compiler-artifact messages with executables for the same invocation.","commonSituations":"A workspace with multiple binary targets where the code lens resolves to an ambiguous cargo invocation; running a crate that produces both a dylib and a bin; or the artifact filter logic at lines 84-92 lets through more than expected (e.g. a profile.test flag is set on a non-test artifact).","solutions":["Specify the exact binary or test target in the cargoArgs (e.g. add '--bin <name>' or '--test <name>') so cargo produces a single artifact.","Check the generated cargo command in the error context and narrow its scope.","If this is a rust-analyzer bug (filter not narrowing correctly), report it with the cargo command and the artifact list from 'cargo build --message-format=json'."],"exampleFix":"// before: ambiguous, produces multiple artifacts\nargs.cargoArgs = ['run']\n// after: specify the binary explicitly\nargs.cargoArgs = ['run', '--bin', 'my-binary']","handlingStrategy":"validation","validationCode":"// Before calling executableFromArgs, narrow the cargo args to a single target.\nfunction ensureSingleArtifact(cargoArgs: string[]): string[] {\n  // If no explicit --bin/--test/--example is given and the workspace has multiple bins,\n  // require the caller to specify one.\n  if (cargoArgs[0] === 'run' && !cargoArgs.some(a => a.startsWith('--bin') || a.startsWith('--example'))) {\n    throw new Error('Multiple binaries possible. Specify --bin <name>.');\n  }\n  return cargoArgs;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const exe = await cargo.executableFromArgs(args);\n} catch (e) {\n  if (e.message === 'Multiple compilation artifacts are not supported.') {\n    // Prompt user to pick which binary\n    const choice = await vscode.window.showQuickPick(binNames, {\n      placeHolder: 'Select which binary to run'\n    });\n    if (choice) {\n      args.cargoArgs.push('--bin', choice);\n      // retry\n    }\n  }\n  throw e;\n}","preventionTips":["Always specify --bin <name> when running in a workspace with multiple binary targets.","Use --test <name> for specific test targets to avoid ambiguity.","Review the ArtifactSpec.filter logic for test/bench specs to ensure it narrows correctly."],"tags":["rust-analyzer","cargo","artifacts","ambiguity","typescript"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}