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

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

Error message

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

What it means

find_project_manifest_exact joins `file` to `pwd` and checks existence; if that exact file is not present it bails. Unlike find_root_manifest_for_wd this does not walk ancestors — it only looks in the single given directory for the named file.

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 0e07a15537)

Solutions

  1. Confirm the expected file exists in the target directory: `ls <dir>/<file>`.
  2. Fix the workspace `members`/`default-members` paths in the root Cargo.toml.
  3. Re-vendor or re-checkout the dependency that is missing its manifest.
  4. Correct any typo in the directory or filename being requested.

Example fix

# root Cargo.toml before
members = ["crates/foo", "crates/bar"]
# but crates/bar/ has no Cargo.toml

# after: remove the missing member or add its manifest
members = ["crates/foo"]
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn ensure_member_manifest(pwd: &Path, file: &str) -> Result<(), anyhow::Error> {
    let p = pwd.join(file);
    if !p.exists() { anyhow::bail!("{p:?} missing; check workspace `members` paths"); }
    Ok(())
}

Type guard

fn member_manifest_present(pwd: &std::path::Path, file: &str) -> bool {
    pwd.join(file).exists()
}

Try / catch

match find_project_manifest_exact(pwd, file) {
    Err(e) if e.to_string().contains("Could not find") => {
        eprintln!("{file} missing in {pwd:?}; verify workspace members/globs");
        return Err(e);
    }
    r => r,
}

Prevention

When it happens

Trigger: Calling cargo internals (or a path that resolves through them) requesting a specific manifest file in a specific directory where that file does not exist, e.g. looking for `Cargo.toml` in a workspace member path that lacks one.

Common situations: A workspace member referenced in the root manifest whose directory is missing its Cargo.toml; a typo in a member path; a vendored/checked-out dependency missing its manifest; stale workspace `members` glob pointing at an empty dir.

Related errors


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