rust-lang/cargo · error
could not find ` ` in ` ` or any parent directory, but…
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 ancestors of cwd looking for Cargo.toml. If it never finds the correctly-cased file but does encounter a lowercase cargo.toml somewhere up the tree, it reports the case mismatch — a common failure on case-sensitive filesystems.
Solutions
- Rename the file to Cargo.toml: `git mv cargo.toml Cargo.toml` (or plain mv if untracked).
- On case-insensitive filesystems use `git mv -f` with a two-step rename to force the case change in git.
- Verify with `ls -la | grep -i cargo.toml` that the correct case is present.
Example fix
# before # ls # cargo.toml # after # git mv cargo.toml Cargo.toml # git commit -m "Fix manifest filename casing"
Defensive patterns
Strategy: validation
Validate before calling
use std::path::Path;
fn find_correctly_cased_manifest(cwd: &Path) -> Result<PathBuf, String> {
for dir in paths::ancestors(cwd, None) {
let p = dir.join("Cargo.toml");
if p.is_file() { return Ok(p); }
if dir.join("cargo.toml").is_file() {
return Err(format!("found lowercase cargo.toml at {}; rename to Cargo.toml", dir.display()));
}
}
Err("no Cargo.toml found".into())
} Type guard
fn manifest_case_is_correct(dir: &std::path::Path) -> bool {
dir.join("Cargo.toml").is_file()
} Prevention
- On case-sensitive filesystems, always create the manifest as `Cargo.toml` (capital C, capital T).
- Add a CI lint that fails if any `cargo.toml` (lowercase) appears in the repo.
- After cloning on Linux, run `git ls-files | grep -i 'cargo.toml'` to spot mis-cased manifests.
When it happens
Trigger: Running any cargo command from inside a directory tree where the manifest was created as `cargo.toml` (lowercase) on a case-sensitive filesystem (Linux default).
Common situations: File created on macOS/Windows and committed with wrong case; editor autocorrect lowercased the filename; clone on Linux of a repo with a misnamed manifest.
Related errors
- can only edit absolute paths, got
- can't find library ` `, rename file to `src/lib.rs` or…
- `cargo init` cannot be run on existing Cargo packages help…
- Could not find ` ` in
- could not find ` ` in ` ` or any parent directory
AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11).
Data as JSON: /api/errors/cae0bde5bbcde376.
Report an issue: GitHub.
Appendix: 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 eb98b54bc9)