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

manifest path `{}` does not exist

Error message

manifest path `{}` does not exist

What it means

root_manifest joins the `--manifest-path` argument to the cwd and normalizes it; if the resulting path does not exist on disk, Cargo bails. This is the first existence check before the directory/file checks.

Source

Thrown at src/util/command_prelude.rs:1056

    }
}

pub fn values(args: &ArgMatches, name: &str) -> Vec<String> {
    args._values_of(name)
}

pub fn values_os(args: &ArgMatches, name: &str) -> Vec<OsString> {
    args._values_of_os(name)
}

pub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> CargoResult<PathBuf> {
    if let Some(manifest_path) = manifest_path {
        let path = gctx.cwd().join(manifest_path);
        // In general, we try to avoid normalizing paths in Cargo,
        // but in this particular case we need it to fix #3586.
        let path = paths::normalize_path(&path);
        if !path.exists() {
            anyhow::bail!("manifest path `{}` does not exist", manifest_path.display())
        } else if path.is_dir() {
            let child_path = path.join("Cargo.toml");
            let suggested_path = if child_path.exists() {
                format!("\nhelp: {} exists", child_path.display())
            } else {
                "".to_string()
            };
            anyhow::bail!(
                "manifest path `{}` is a directory but expected a file{suggested_path}",
                manifest_path.display()
            )
        } else if !path.ends_with("Cargo.toml") && !crate::workspace::parser::is_embedded(&path) {
            if gctx.cli_unstable().script {
                anyhow::bail!(
                    "the manifest-path must be a path to a Cargo.toml or script file: `{}`",
                    path.display()
                )
            } else {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Verify the path exists: `ls <path>` and correct typos.
  2. Use an absolute path to avoid cwd ambiguity.
  3. If you meant the workspace root, omit `--manifest-path` and let Cargo walk up to find Cargo.toml.
  4. In CI, print `pwd` and `find . -name Cargo.toml` to confirm location.

Example fix

# before
cargo build --manifest-path Cargo.tml

# after
cargo build --manifest-path Cargo.toml
# or simply
cargo build
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn ensure_manifest_exists(p: &Path) -> Result<(), anyhow::Error> {
    if !p.exists() {
        anyhow::bail!("manifest path `{}` does not exist; check the path/cwd", p.display());
    }
    Ok(())
}
// call before cargo::ops::* that takes a manifest path

Type guard

fn manifest_exists(p: &std::path::Path) -> bool { p.exists() && p.is_file() }

Try / catch

match root_manifest(Some(path), gctx) {
    Err(e) if e.to_string().contains("does not exist") => {
        eprintln!("--manifest-path file not found; verify cwd/typos");
        return Err(e);
    }
    r => r,
}

Prevention

When it happens

Trigger: Running any cargo command with `--manifest-path <nonexistent>`, e.g. `cargo build --manifest-path /nope/Cargo.toml` where the file is absent; a typo in the path; a relative path resolved against an unexpected cwd.

Common situations: Typos in `--manifest-path`; running cargo from the wrong working directory so a relative path does not resolve; CI checking out into a different directory than the script assumes; leftover path from a moved/deleted project.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/0007bc9647e7f3ce.json. Report an issue: GitHub.