rust-lang/rust · error · Error

No compilation artifacts

Error message

No compilation artifacts

What it means

Thrown by Cargo.executableFromArgs() at toolchain.ts:115-116 when getArtifacts() returns an empty array. getArtifacts() runs cargo with --message-format=json and collects CompilationArtifact entries only for messages where reason is 'compiler-artifact', an executable path is present, and (it's a non-buildscript binary OR a test profile). If zero messages match, no runnable executable was produced.

Source

Thrown at src/tools/rust-analyzer/editors/code/src/toolchain.ts:116

                (stderr) => log.error(stderr),
                env,
            );
        } catch (err) {
            log.error(`Cargo invocation has failed: ${err}`);
            throw new Error(`Cargo invocation has failed: ${err}`, { cause: err });
        }

        return spec.filter?.(artifacts) ?? artifacts;
    }

    async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {
        const artifacts = await this.getArtifacts(
            Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),
            runnableArgs.environment,
        );

        if (artifacts.length === 0) {
            throw new Error("No compilation artifacts");
        } else if (artifacts.length > 1) {
            throw new Error("Multiple compilation artifacts are not supported.");
        }

        const artifact = unwrapUndefinable(artifacts[0]);
        return artifact.fileName;
    }

    private async runCargo(
        cargoArgs: string[],
        onStdoutJson: (obj: CompilerMessage) => void,
        onStderrString: (data: string) => void,
        env?: Record<string, string>,
    ): Promise<number> {
        const path = await cargoPath(env);
        return await new Promise((resolve, reject) => {
            const cargo = cp.spawn(path, cargoArgs, {
                stdio: ["ignore", "pipe", "pipe"],

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Verify the target actually produces an executable: run 'cargo build --bin <name>' or 'cargo test --no-run' in the terminal and confirm a binary is emitted.
  2. If running a test, ensure there are #[test] functions or a [[test]] target in Cargo.toml.
  3. Check that the cargoArgs passed to executableFromArgs are correct (e.g. 'run' maps to 'build', 'test' needs test artifacts).
  4. Update rust-analyzer to the latest version if the cargo JSON message format has changed.
Defensive patterns

Strategy: validation

Validate before calling

// Before calling executableFromArgs, verify the target produces an artifact.
// Check Cargo.toml for [[bin]] or [[test]] targets matching the runnable.
function targetProducesBinary(cargoArgs: string[]): boolean {
  // 'run'/'build' requires a [[bin]] target; 'test' requires test artifacts
  const cmd = cargoArgs[0];
  if (cmd === 'run' || cmd === 'build') {
    // verify a [[bin]] target exists — caller should parse Cargo.toml
    return true; // placeholder for actual check
  }
  return true;
}

Try / catch

try {
  const exe = await cargo.executableFromArgs(args);
} catch (e) {
  if (e.message === 'No compilation artifacts') {
    vscode.window.showWarningMessage(
      'This target does not produce a runnable binary. Use a [[bin]] or [[test]] target.'
    );
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: executableFromArgs() is called when the user invokes a Run/Debug code lens. getArtifacts() returns []. This happens when: the target produces only a library (no bin/test artifact), the artifact filter for 'test'/'bench' specs removes all entries (line 64: result.filter filters by isTest but no test artifacts exist), cargo succeeded but emitted no 'compiler-artifact' message with an executable field, or the crate_type/kind didn't match the bin/test checks at lines 84-92.

Common situations: Clicking Run on a code lens for a library crate that has no binary or test target; running a 'bench' command on a crate without benchmarks; the cargo artifact JSON schema changed and the filter no longer matches; or trying to run an example/bench that produced a different artifact kind.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/e82ce14a96c03272. Report an issue: GitHub.