rust-lang/cargo · error · anyhow::Error
embedded manifest `{}` requires `-Zscript`
Error message
embedded manifest `{}` requires `-Zscript` What it means
root_manifest detects via workspace::parser::is_embedded that the given path is an embedded manifest (a `.rs` file with a leading `//! ```cargo` block) but the `-Zscript` unstable flag is not enabled. Embedded manifests are part of cargo script (RFC 3424) and require the nightly `-Zscript` flag.
Source
Thrown at src/util/command_prelude.rs:1082
anyhow::bail!(
"manifest path `{}` is a directory but expected a file{suggested_path}",
manifest_path.display()
)
} else if !path.ends_with("Cargo.toml") && !crate::workspace::parser::is_embedded(&path) {
if gctx.cli_unstable().script {
anyhow::bail!(
"the manifest-path must be a path to a Cargo.toml or script file: `{}`",
path.display()
)
} else {
anyhow::bail!(
"the manifest-path must be a path to a Cargo.toml file: `{}`",
path.display()
)
}
}
if crate::workspace::parser::is_embedded(&path) && !gctx.cli_unstable().script {
anyhow::bail!("embedded manifest `{}` requires `-Zscript`", path.display())
}
Ok(path)
} else {
find_root_manifest_for_wd(gctx.cwd())
}
}
pub fn get_registry_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {
let gctx = new_gctx_for_completions()?;
if let Ok(Some(registries)) =
gctx.get::<Option<HashMap<String, HashMap<String, String>>>>("registries")
{
Ok(registries
.keys()
.map(|name| clap_complete::CompletionCandidate::new(name.to_owned()))
.collect())
} else {View on GitHub (pinned to 0e07a15537)
Solutions
- Re-run with `-Zscript` on a nightly toolchain: `cargo +nightly run -Zscript --manifest-path script.rs`.
- If you did not mean to use a script, point `--manifest-path` at a real `Cargo.toml`.
- Configure your IDE/wrapper to pass `-Zscript` when invoking on script files.
Example fix
# before cargo run --manifest-path script.rs # after cargo +nightly run -Zscript --manifest-path script.rs
Defensive patterns
Strategy: validation
Validate before calling
use std::path::Path;
fn require_script_flag_if_embedded(p: &Path, script_enabled: bool) -> Result<(), anyhow::Error> {
if cargo::workspace::parser::is_embedded(p) && !script_enabled {
anyhow::bail!("embedded manifest requires nightly cargo with -Zscript");
}
Ok(())
}
// script_enabled = gctx.cli_unstable().script Type guard
fn needs_script_flag(p: &std::path::Path) -> bool {
cargo::workspace::parser::is_embedded(p)
} Try / catch
match root_manifest(Some(path), gctx) {
Err(e) if e.to_string().contains("requires `-Zscript`") => {
eprintln!("re-run with: cargo +nightly run -Zscript --manifest-path {path}");
return Err(e);
}
r => r,
} Prevention
- Reserve embedded `.rs` manifests for nightly + `-Zscript`.
- Configure IDE/wrappers to add `-Zscript` when launching script files.
When it happens
Trigger: Passing an embedded-manifest `.rs` script file as `--manifest-path` on a cargo build that was not launched with `-Zscript` (e.g. stable cargo, or nightly without the flag).
Common situations: Running a cargo script with stable cargo; nightly cargo invoked without `-Zscript`; a wrapper/IDE that passes the script path but not the unstable flag.
Related errors
- the manifest-path must be a path to a Cargo.toml or script f
- the manifest-path must be a path to a Cargo.toml file: `{}`
- running the file `{cmd}` requires `-Zscript`
- no such file or subcommand `{cmd}`{is_dir}{suggested_command
- manifest path `{}` does not exist
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/fa464b7d46b1d42f.json.
Report an issue: GitHub.