rust-lang/cargo · error

Could not find ` ` in

Error message

Could not find `{}` in `{}`

What it means

find_project_manifest_exact(pwd, file) checks for a specific named file directly in pwd and bails if it is absent. Unlike the ancestor-walking variant, this checks exactly one directory.

Solutions

  1. Confirm the file exists at the exact pwd given (not a subdirectory or ancestor).
  2. Fix the manifest reference (members/patch/exclude) to the real path.
  3. Recreate the missing file if it was accidentally deleted.

Example fix

# before (Cargo.toml)
# [workspace]
# members = ["crates/missing"]

# after
# [workspace]
# members = ["crates/present"]   # corrected path
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;

fn require_file_in_dir(dir: &Path, file: &str) -> Result<PathBuf, String> {
    let p = dir.join(file);
    if p.is_file() { Ok(p) } else { Err(format!("{file} not found in {}", dir.display())) }
}

Type guard

fn file_present(dir: &std::path::Path, file: &str) -> bool {
    dir.join(file).is_file()
}

Prevention

When it happens

Trigger: An internal lookup for a concrete file (e.g. a workspace member's manifest, Cargo.lock, or a patch target) where the file does not exist in the specified directory.

Common situations: Referencing a path member in Cargo.toml that was deleted or not yet created; a patch table pointing at a missing manifest; an outdated workspace layout after a refactor.

Related errors


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

Appendix: source

Thrown at src/util/important_paths.rs:43

            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() {
        Ok(manifest)
    } else {
        anyhow::bail!("Could not find `{}` in `{}`", file, pwd.display())
    }
}

View on GitHub (pinned to eb98b54bc9)