rust-lang/cargo · error
parsing ` ` requires `-Zscript
Error message
parsing `{}` requires `-Zscript` What it means
Thrown by read_toml_string when the manifest file is detected as an embedded (single-file script) manifest — identified by frontmatter or shebang — but the -Zscript unstable feature is not enabled in the global context. Embedded manifests are an unstable cargo feature; without the gate, cargo refuses to expand the script's frontmatter into a real manifest.
Solutions
- Enable the unstable feature: add -Zscript to the cargo invocation (requires nightly cargo).
- If you did not intend an embedded manifest, remove the frontmatter or shebang from the file.
- Ensure your cargo is a nightly build that supports -Zscript.
Example fix
# before cargo run ./script.rs # after (nightly) cargo +nightly run -Zscript ./script.rs
Defensive patterns
Strategy: try-catch
Validate before calling
fn check_script_feature_enabled(gctx: &GlobalContext) -> bool {
gctx.cli_unstable().script
} Try / catch
match parse_manifest(path, gctx) {
Ok(m) => m,
Err(e) if e.to_string().contains("requires `-Zscript`") => {
eprintln!("Re-run with nightly cargo and -Zscript for embedded manifests");
return Err(e);
}
Err(e) => return Err(e),
} Prevention
- Pass -Zscript on nightly cargo when working with single-file scripts.
- Detect embedded manifests (frontmatter/shebang) and branch your tooling accordingly.
- Keep a nightly toolchain installed if you use cargo scripts.
When it happens
Trigger: Running cargo against a .rs file that begins with a frontmatter (--- cargo ...) or shebang (#!/...) when -Zscript is not in the unstable flags. Detected via is_embedded(path) being true and gctx.cli_unstable().script being false.
Common situations: A user tries `cargo run script.rs` on a nightly feature file without -Zscript. A stable cargo toolchain encounters a single-file cargo script. The nightly flag was dropped from a wrapper command.
Related errors
- parsing ` ` requires `-Zscript
- not allowed in embedded manifests
- not implemented
- artifact-dir was not locked during clean
- cannot publish with `open-namespaces`
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/f4a22a574dad5e24.
Report an issue: GitHub.
Appendix: source
Thrown at src/workspace/parser/mod.rs:179
mut document: toml::Spanned<toml::de::DeTable<'_>>,
) -> toml::Spanned<toml::de::DeTable<'static>> {
document.get_mut().make_owned();
// SAFETY: `DeTable::make_owned` ensures no borrows remain and the lifetime does not affect
// layout
unsafe {
std::mem::transmute::<
toml::Spanned<toml::de::DeTable<'_>>,
toml::Spanned<toml::de::DeTable<'static>>,
>(document)
}
}
#[tracing::instrument(skip_all)]
fn read_toml_string(path: &Path, is_embedded: bool, gctx: &GlobalContext) -> CargoResult<String> {
let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?;
if is_embedded {
if !gctx.cli_unstable().script {
anyhow::bail!("parsing `{}` requires `-Zscript`", path.display());
}
contents = embedded::expand_manifest(&contents)
.map_err(|e| emit_frontmatter_diagnostic(e, &contents, path, gctx))?;
}
Ok(contents)
}
#[tracing::instrument(skip_all)]
fn parse_document(contents: &str) -> Result<toml::Spanned<toml::de::DeTable<'_>>, toml::de::Error> {
toml::de::DeTable::parse(&contents)
}
#[tracing::instrument(skip_all)]
fn deserialize_toml(
document: &toml::Spanned<toml::de::DeTable<'_>>,
) -> Result<manifest::TomlManifest, toml::de::Error> {
let mut unused = BTreeSet::new();
let deserializer = toml::de::Deserializer::from(document.clone());View on GitHub (pinned to 98a09e7e7d)