{"record":{"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":null,"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/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/util/command_prelude.rs#L1052-L1088","documentation":"With -Zscript enabled, a --manifest-path that exists, is not a directory, and does not end in Cargo.toml nor is an embedded script is rejected. The script feature broadens acceptance to single-file .rs scripts with embedded manifests, but arbitrary files still fail.","triggerScenarios":"Running `cargo <cmd> --manifest-path foo.txt -Zscript` where foo.txt is neither Cargo.toml nor a recognized embedded-manifest .rs script.","commonSituations":"Pointing --manifest-path at a non-manifest file expecting the script feature to accept it; wrong file extension for a single-file package.","solutions":["Point --manifest-path at a Cargo.toml, or at an .rs file whose leading comment block contains an embedded Cargo manifest.","Confirm the file actually has the embedded manifest syntax cargo expects."],"exampleFix":"# before\n# cargo build --manifest-path script.txt -Zscript\n\n# after\n# rename to script.rs with embedded manifest, then:\n# cargo build --manifest-path script.rs -Zscript","handlingStrategy":"validation","validationCode":"use std::path::Path;\n\nfn validate_script_manifest(p: &Path, script_unstable: bool) -> Result<(), String> {\n    if !script_unstable {\n        return Err(\"embedded/script manifests require -Zscript (nightly)\".into());\n    }\n    if !(p.ends_with(\"Cargo.toml\") || cargo::workspace::parser::is_embedded(p)) {\n        return Err(format!(\"{p:?} is not a Cargo.toml or embedded .rs manifest\"));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use single-file .rs scripts on nightly with -Zscript.","Keep the embedded manifest syntax identical to what cargo:workspace::parser expects."],"tags":["manifest","paths","script","unstable"],"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"}