rust-lang/rust · error · anyhow::Error

rust-analyzer analysis-stats produced no pgo files. This is

Error message

rust-analyzer analysis-stats produced no pgo files. This is a bug in rust-analyzer; please file an issue.

What it means

Bailed by the PGO training step in xtask/pgo.rs when, after running rust-analyzer analysis-stats with profiling instrumentation, no .profraw files appear in the output directory. profraw files are what llvm-profdata merges; their absence means the instrumented analysis-stats run did not actually produce profile data.

Source

Thrown at src/tools/rust-analyzer/xtask/src/pgo.rs:68

    )
    .run()
    .context("cannot generate PGO profiles")?;

    // Merge profiles into a single file
    let merged_profile = pgo_dir.join("merged.profdata");
    let profile_files = std::fs::read_dir(pgo_dir)?
        .filter_map(|entry| {
            let entry = entry.ok()?;
            if entry.path().extension() == Some(OsStr::new("profraw")) {
                Some(entry.path().to_str().unwrap().to_owned())
            } else {
                None
            }
        })
        .collect::<Vec<_>>();

    if profile_files.is_empty() {
        anyhow::bail!(
            "rust-analyzer analysis-stats produced no pgo files. This is a bug in rust-analyzer; please file an issue."
        );
    }

    cmd!(sh, "{llvm_profdata} merge {profile_files...} -o {merged_profile}").run().context(
        "cannot merge PGO profiles. Do you have the rustup `llvm-tools` component installed?",
    )?;

    Ok(merged_profile)
}

/// Downloads a crate from GitHub, stores it into `pgo_dir` and returns a path to it.
fn download_crate_for_training(sh: &Shell, pgo_dir: &Path, repo: &str) -> anyhow::Result<PathBuf> {
    let mut it = repo.splitn(2, '@');
    let repo = it.next().unwrap();
    let revision = it.next();

    // FIXME: switch to `--revision` here around 2035 or so

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Confirm the rust-analyzer binary used for analysis-stats is the instrumented one (built with the PGO instrumentation flags the xtask sets).
  2. Check LLVM_PROFILE_FILE is set to a writable path pattern in the directory pgo_dir reads from, and the directory exists.
  3. Re-run analysis-stats standalone with verbose logging to see if it completed; if it errored, fix that first.
  4. Clear pgo_dir before the run so leftover files don't mask the absence of new profraw files.

Example fix

// before
if profile_files.is_empty() {
    anyhow::bail!(
        "rust-analyzer analysis-stats produced no pgo files. \
         This is a bug in rust-analyzer; please file an issue."
    );
}

// after: distinguish user-fixable causes from a real r-a bug
if profile_files.is_empty() {
    let profraw_glob = pgo_dir.join("*.profraw");
    anyhow::bail!(
        "rust-analyzer analysis-stats produced no pgo files (looked for {}). \
         Verify the binary was built with instrumentation and \
         LLVM_PROFILE_FILE was set; only file an r-a issue if both are correct.",
        profraw_glob.display()
    );
}
Defensive patterns

Strategy: validation

Validate before calling

// Before the PGO run, confirm the r-a binary is instrumented and the profile
// dir is writable:
fn instrumented_and_writable(bin: &Path, dir: &Path) -> bool {
    let instr = std::process::Command::new(bin).arg("--version")
        .output().map(|o| String::from_utf8_lossy(&o.stdout).contains("instrumented")).unwrap_or(false);
    instr && std::fs::create_dir_all(dir).is_ok()
}
// Also export LLVM_PROFILE_FILE="<dir>/%m-%p.profraw".

Type guard

null

Try / catch

match pgo::build(&sh, &pgo_dir) {
    Ok(_) => Ok(()),
    Err(e) if e.to_string().contains("no pgo files") => {
        eprintln!("ensure the r-a binary is instrumented and LLVM_PROFILE_FILE is set");
        Err(e)
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: Running `cargo xtask pgo` (or the analysis-stats PGO subcommand) where the rust-analyzer binary used was not built with -Cinstrument-coverage / the LLVM_PROFILE_FILE env var was not set correctly, or analysis-stats exited before writing any profile.

Common situations: Building rust-analyzer for PGO without the instrumented profile flags; LLVM_PROFILE_FILE pointing at a path the process can't write (read-only dir); analysis-stats crashing early so no basic block is ever executed; a stale pgo_dir that already contained only non-profraw files.

Related errors


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