rust-lang/cargo · error

embedded manifest ` ` requires `-Zscript

Error message

embedded manifest `{}` requires `-Zscript`

What it means

root_manifest() recognizes the --manifest-path file as an embedded manifest (a single-file .rs package with embedded TOML), but gctx.cli_unstable().script is false. Embedded manifests are gated behind the unstable -Zscript feature.

Solutions

  1. Run on nightly with -Zscript: `cargo +nightly build --manifest-path script.rs -Zscript`.
  2. Convert the single-file package into a normal Cargo project with a Cargo.toml if you must stay on stable.

Example fix

# before
# cargo build --manifest-path script.rs

# after
# cargo +nightly build --manifest-path script.rs -Zscript
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;

fn require_script_feature(p: &Path, script_unstable: bool) -> Result<(), String> {
    if cargo::workspace::parser::is_embedded(p) && !script_unstable {
        return Err(format!("embedded manifest {p:?} requires -Zscript (nightly)"));
    }
    Ok(())
}

Type guard

fn needs_zscript(p: &std::path::Path) -> bool {
    cargo::workspace::parser::is_embedded(p)
}

Prevention

When it happens

Trigger: Passing a single-file .rs script with an embedded manifest to stable Cargo, or nightly Cargo without -Zscript.

Common situations: Trying the RFC 3423 single-file-package workflow on stable; a CI job not passing -Zscript.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/fa464b7d46b1d42f. Report an issue: GitHub.

Appendix: 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 98a09e7e7d)