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

the manifest-path must be a path to a Cargo.toml file: `{}`

Error message

the manifest-path must be a path to a Cargo.toml file: `{}`

What it means

root_manifest, WITHOUT `-Zscript`, requires the manifest path to end in `Cargo.toml`. Any other filename (including a `.rs` script) is rejected because embedded/single-file scripts are gated behind the unstable `-Zscript` feature.

Source

Thrown at src/util/command_prelude.rs:1075

        } 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 {
                anyhow::bail!(
                    "the manifest-path must be a path to a Cargo.toml file: `{}`",
                    path.display()
                )
            }
        }
        if crate::workspace::parser::is_embedded(&path) && !gctx.cli_unstable().script {
            anyhow::bail!("embedded manifest `{}` requires `-Zscript`", path.display())
        }
        Ok(path)
    } else {
        find_root_manifest_for_wd(gctx.cwd())
    }
}

pub fn get_registry_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {
    let gctx = new_gctx_for_completions()?;

    if let Ok(Some(registries)) =

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Use a path ending in `Cargo.toml`.
  2. If you intended to run a single-file script, use a nightly toolchain and pass `-Zscript`.
  3. Correct the filename typo.

Example fix

# before
cargo run --manifest-path main.rs

# after (script on nightly)
cargo +nightly run -Zscript --manifest-path main.rs
# or use a normal project
cargo run --manifest-path Cargo.toml
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn validate_manifest_path_stable(p: &Path) -> Result<(), anyhow::Error> {
    if !p.ends_with("Cargo.toml") && !cargo::workspace::parser::is_embedded(p) {
        anyhow::bail!("manifest-path must end in Cargo.toml on stable cargo");
    }
    Ok(())
}

Type guard

fn looks_like_cargo_toml(p: &std::path::Path) -> bool { p.ends_with("Cargo.toml") }

Try / catch

match root_manifest(Some(path), gctx) {
    Err(e) if e.to_string().contains("must be a path to a Cargo.toml file") => {
        eprintln!("on stable cargo, --manifest-path must be a Cargo.toml");
        return Err(e);
    }
    r => r,
}

Prevention

When it happens

Trigger: Passing `--manifest-path` to a non-Cargo.toml file (e.g. a `.rs` script, `Cargo.lock`, or arbitrary file) on a stable cargo invocation without `-Zscript`.

Common situations: Trying to run a single-file cargo script on stable cargo (script support is nightly-only); typoing the manifest filename; pointing at a generated artifact file.

Related errors


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