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

could not find `{}` in `{}` or any parent directory, but fou

Error message

could not find `{}` in `{}` or any parent directory, but found cargo.toml please try to rename it to Cargo.toml

What it means

find_root_manifest_for_wd walks cwd and all ancestors looking for `Cargo.toml`. If none is found but a lowercase `cargo.toml` exists somewhere in that ancestor chain, Cargo reports it and asks the user to rename — because on case-sensitive filesystems (Linux) `cargo.toml` is not recognized.

Source

Thrown at src/util/important_paths.rs:22

/// Finds the root `Cargo.toml`.
pub fn find_root_manifest_for_wd(cwd: &Path) -> CargoResult<PathBuf> {
    let valid_cargo_toml_file_name = "Cargo.toml";
    let invalid_cargo_toml_file_name = "cargo.toml";
    let mut invalid_cargo_toml_path_exists = false;

    for current in paths::ancestors(cwd, None) {
        let manifest = current.join(valid_cargo_toml_file_name);
        if manifest.exists() {
            return Ok(manifest);
        }
        if current.join(invalid_cargo_toml_file_name).exists() {
            invalid_cargo_toml_path_exists = true;
        }
    }

    if invalid_cargo_toml_path_exists {
        anyhow::bail!(
            "could not find `{}` in `{}` or any parent directory, but found cargo.toml please try to rename it to Cargo.toml",
            valid_cargo_toml_file_name,
            cwd.display()
        )
    } else {
        anyhow::bail!(
            "could not find `{}` in `{}` or any parent directory",
            valid_cargo_toml_file_name,
            cwd.display()
        )
    }
}

/// Returns the path to the `file` in `pwd`, if it exists.
pub fn find_project_manifest_exact(pwd: &Path, file: &str) -> CargoResult<PathBuf> {
    let manifest = pwd.join(file);

    if manifest.exists() {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Rename the file: `mv cargo.toml Cargo.toml`.
  2. On case-insensitive FS, use `git mv cargo.toml Cargo.toml` or a two-step rename (`mv cargo.toml tmp && mv tmp Cargo.toml`) to actually change the case.
  3. Re-run cargo from the project root after renaming.

Example fix

# before: project contains ./cargo.toml
mv cargo.toml Cargo.toml
# after: cargo build works
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn warn_lowercase_manifest(cwd: &Path) {
    for d in cargo_util::paths::ancestors(cwd, None) {
        if d.join("cargo.toml").exists() && !d.join("Cargo.toml").exists() {
            eprintln!("warning: found lowercase cargo.toml in {}; rename to Cargo.toml", d.display());
        }
    }
}

Type guard

fn has_lowercase_cargo_toml(cwd: &std::path::Path) -> bool {
    cargo_util::paths::ancestors(cwd, None)
        .any(|d| d.join("cargo.toml").exists())
}

Try / catch

match find_root_manifest_for_wd(cwd) {
    Err(e) if e.to_string().contains("found cargo.toml") => {
        eprintln!("rename cargo.toml -> Cargo.toml (case-sensitive FS)");
        return Err(e);
    }
    r => r,
}

Prevention

When it happens

Trigger: Running cargo in a directory tree where the manifest was mistakenly named `cargo.toml` (lowercase) instead of `Cargo.toml`, typically after copying a project from a case-insensitive filesystem (macOS/Windows) to Linux.

Common situations: Project created/renamed on macOS or Windows where `cargo.toml` and `Cargo.toml` are the same file, then deployed to Linux; a typo when creating the manifest; tooling that lowercased the filename.

Related errors


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