{"id":"bc9ed9216e9bc163","repo":"rust-lang/cargo","slug":"the-manifest-path-must-be-a-path-to-a-cargo-toml-f","errorCode":null,"errorMessage":"the manifest-path must be a path to a Cargo.toml file: `{}`","messagePattern":"the manifest-path must be a path to a Cargo\\.toml file: `(.+?)`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":1075,"sourceCode":"        } 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())\n        }\n        Ok(path)\n    } else {\n        find_root_manifest_for_wd(gctx.cwd())\n    }\n}\n\npub fn get_registry_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {\n    let gctx = new_gctx_for_completions()?;\n\n    if let Ok(Some(registries)) =","sourceCodeStart":1057,"sourceCodeEnd":1093,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L1057-L1093","documentation":"root_manifest, WITHOUT `-Zscript`, requires the manifest path to end in `Cargo.toml`. Any other filename (including a `.rs` script) is rejected because embedded/single-file scripts are gated behind the unstable `-Zscript` feature.","triggerScenarios":"Passing `--manifest-path` to a non-Cargo.toml file (e.g. a `.rs` script, `Cargo.lock`, or arbitrary file) on a stable cargo invocation without `-Zscript`.","commonSituations":"Trying to run a single-file cargo script on stable cargo (script support is nightly-only); typoing the manifest filename; pointing at a generated artifact file.","solutions":["Use a path ending in `Cargo.toml`.","If you intended to run a single-file script, use a nightly toolchain and pass `-Zscript`.","Correct the filename typo."],"exampleFix":"# before\ncargo run --manifest-path main.rs\n\n# after (script on nightly)\ncargo +nightly run -Zscript --manifest-path main.rs\n# or use a normal project\ncargo run --manifest-path Cargo.toml","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn validate_manifest_path_stable(p: &Path) -> Result<(), anyhow::Error> {\n    if !p.ends_with(\"Cargo.toml\") && !cargo::workspace::parser::is_embedded(p) {\n        anyhow::bail!(\"manifest-path must end in Cargo.toml on stable cargo\");\n    }\n    Ok(())\n}","typeGuard":"fn looks_like_cargo_toml(p: &std::path::Path) -> bool { p.ends_with(\"Cargo.toml\") }","tryCatchPattern":"match root_manifest(Some(path), gctx) {\n    Err(e) if e.to_string().contains(\"must be a path to a Cargo.toml file\") => {\n        eprintln!(\"on stable cargo, --manifest-path must be a Cargo.toml\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["On stable cargo always pass a path ending in Cargo.toml.","Use nightly + `-Zscript` for single-file scripts."],"tags":["cli","manifest","script","path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}