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
- Confirm the file exists at the exact pwd given (not a subdirectory or ancestor).
- Fix the manifest reference (members/patch/exclude) to the real path.
- 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
- Keep workspace member paths in Cargo.toml in sync with the on-disk layout.
- After moving/renaming crates, update members/patch/exclude immediately.
- Add a CI check that every declared member path resolves.
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
- could not find ` ` in ` ` or any parent directory
- cannot override `workspace.lints` in `lints`, either remove…
- could not find ` ` in ` ` or any parent directory, but…
- found a virtual manifest at
- ` .workspace = false` is unsupported
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)