{"id":"c918b5e4a5536bc3","repo":"rust-lang/cargo","slug":"the-manifest-path-must-be-a-path-to-a-cargo-toml-o","errorCode":null,"errorMessage":"the manifest-path must be a path to a Cargo.toml or script file: `{}`","messagePattern":"the manifest-path must be a path to a Cargo\\.toml or script file: `(.+?)`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":1070,"sourceCode":"        // 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())\n        }\n        Ok(path)\n    } else {\n        find_root_manifest_for_wd(gctx.cwd())\n    }\n}","sourceCodeStart":1052,"sourceCodeEnd":1088,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L1052-L1088","documentation":"root_manifest, with `-Zscript` enabled, requires the manifest path to either end in `Cargo.toml` or be recognized by workspace::parser::is_embedded (a single `.rs` script with an embedded manifest). If the path is a file but matches neither, it bails. This is the script-aware variant of the manifest-path filename check.","triggerScenarios":"Running with `-Zscript` and `--manifest-path` pointing to a file that is neither `Cargo.toml` nor a recognized embedded-script `.rs` file (e.g. `Cargo.lock`, `README.md`, or a `.rs` file without a valid embedded manifest).","commonSituations":"Experimenting with cargo script (RFC 3424) and passing a non-script `.rs` file; passing the wrong file in a multi-file project; the script file lacks the leading `//! ```cargo` manifest block so is_embedded returns false.","solutions":["Point `--manifest-path` at a `Cargo.toml` or at a `.rs` file containing a valid embedded `//! ```cargo` manifest block.","If the script lacks an embedded manifest, add one (the `cargo.nightly` code-fenced block at the top of the file).","Remove `-Zscript` if you only intend to build a normal Cargo.toml project."],"exampleFix":"# before (script.rs has no embedded manifest)\ncargo run -Zscript --manifest-path script.rs\n\n# after: ensure script.rs begins with\n# //! ```cargo\n# //! [dependencies]\n# //! serde = \"1\"\n# //! ```\ncargo run -Zscript --manifest-path script.rs","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn validate_script_manifest(p: &Path) -> Result<(), anyhow::Error> {\n    if !p.exists() { anyhow::bail!(\"missing\"); }\n    if p.is_dir() { anyhow::bail!(\"is a directory\"); }\n    let ok = p.ends_with(\"Cargo.toml\") || cargo::workspace::parser::is_embedded(p);\n    if !ok { anyhow::bail!(\"path must be Cargo.toml or an embedded-script .rs file\"); }\n    Ok(())\n}","typeGuard":"fn is_cargo_script_or_manifest(p: &std::path::Path) -> bool {\n    p.ends_with(\"Cargo.toml\") || cargo::workspace::parser::is_embedded(p)\n}","tryCatchPattern":"match root_manifest(Some(path), gctx) {\n    Err(e) if e.to_string().contains(\"Cargo.toml or script file\") => {\n        eprintln!(\"with -Zscript, pass Cargo.toml or a .rs with an embedded manifest\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Only use `-Zscript` on nightly and only with script files containing a `//! ```cargo` block.","Keep regular builds pointed at Cargo.toml."],"tags":["cli","manifest","script","unstable","path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}