rust-lang/cargo · 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

Without -Zscript, root_manifest() requires --manifest-path to end in Cargo.toml (or be an embedded manifest, which itself needs -Zscript). Any other file extension is rejected on stable Cargo.

Solutions

  1. Point --manifest-path at a valid Cargo.toml.
  2. If you intend a single-file script, switch to nightly and pass -Zscript (and rename the file appropriately).

Example fix

# before
# cargo build --manifest-path ./project.toml

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

Strategy: validation

Validate before calling

use std::path::Path;

fn validate_stable_manifest(p: &Path) -> Result<(), String> {
    if p.ends_with("Cargo.toml") { return Ok(()); }
    Err(format!("on stable cargo, --manifest-path must point to a Cargo.toml: {p:?}"))
}

Type guard

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

Prevention

When it happens

Trigger: Stable Cargo invoked with `--manifest-path README.md` or any non-Cargo.toml file.

Common situations: Typo in the path; pointing at a generated/template file that is not a real manifest.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/bc9ed9216e9bc163. Report an issue: GitHub.

Appendix: 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 98a09e7e7d)