{"record":{"id":"3efbb459fb3d482a","repo":"rust-lang/cargo","slug":"manifest-path-is-a-directory-but-expected-a-f","errorCode":null,"errorMessage":"manifest path `{}` is a directory but expected a file{suggested_path}","messagePattern":"manifest path `(.+?)` is a directory but expected a file(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":1064,"sourceCode":"    args._values_of_os(name)\n}\n\npub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> CargoResult<PathBuf> {\n    if let Some(manifest_path) = manifest_path {\n        let path = gctx.cwd().join(manifest_path);\n        // In general, we try to avoid normalizing paths in Cargo,\n        // but in this particular case we need it to fix #3586.\n        let path = paths::normalize_path(&path);\n        if !path.exists() {\n            anyhow::bail!(\"manifest path `{}` does not exist\", manifest_path.display())\n        } else if path.is_dir() {\n            let child_path = path.join(\"Cargo.toml\");\n            let suggested_path = if child_path.exists() {\n                format!(\"\\nhelp: {} exists\", child_path.display())\n            } else {\n                \"\".to_string()\n            };\n            anyhow::bail!(\n                \"manifest path `{}` is a directory but expected a file{suggested_path}\",\n                manifest_path.display()\n            )\n        } else if !path.ends_with(\"Cargo.toml\") && !crate::workspace::parser::is_embedded(&path) {\n            if gctx.cli_unstable().script {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml or script file: `{}`\",\n                    path.display()\n                )\n            } else {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml file: `{}`\",\n                    path.display()\n                )\n            }\n        }\n        if crate::workspace::parser::is_embedded(&path) && !gctx.cli_unstable().script {\n            anyhow::bail!(\"embedded manifest `{}` requires `-Zscript`\", path.display())","sourceCodeStart":1046,"sourceCodeEnd":1082,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/util/command_prelude.rs#L1046-L1082","documentation":"root_manifest() detects that --manifest-path resolves to a directory rather than a file. If that directory contains Cargo.toml, the error appends a help line suggesting the concrete file.","triggerScenarios":"Passing a project directory to --manifest-path, e.g. `cargo build --manifest-path ./mycrate` where mycrate is a folder.","commonSituations":"Confusing the project root directory with the manifest file; copy-pasting a directory from a docs example.","solutions":["Point --manifest-path at the Cargo.toml file inside the directory: `--manifest-path ./mycrate/Cargo.toml`.","Drop --manifest-path and cd into the project; Cargo finds Cargo.toml automatically."],"exampleFix":"# before\n# cargo build --manifest-path ./mycrate\n\n# after\n# cargo build --manifest-path ./mycrate/Cargo.toml","handlingStrategy":"validation","validationCode":"use std::path::Path;\n\nfn resolve_manifest_arg(p: &Path) -> Result<PathBuf, String> {\n    let p = paths::normalize_path(p);\n    if p.is_dir() {\n        let inner = p.join(\"Cargo.toml\");\n        if inner.is_file() { return Ok(inner); }\n        return Err(format!(\"{p:?} is a directory; expected a Cargo.toml file\"));\n    }\n    Ok(p)\n}","typeGuard":"fn looks_like_manifest_file(p: &std::path::Path) -> bool {\n    p.is_file()\n}","tryCatchPattern":null,"preventionTips":["Always pass the Cargo.toml file, not its containing directory, to --manifest-path.","When unsure, omit --manifest-path and cd into the project instead."],"tags":["manifest","paths","cli"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}