{"record":{"id":"f4a22a574dad5e24","repo":"rust-lang/cargo","slug":"parsing-requires-zscript-f4a22a","errorCode":null,"errorMessage":"parsing `{}` requires `-Zscript`","messagePattern":"parsing `(.+?)` requires `-Zscript`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/mod.rs","lineNumber":179,"sourceCode":"    mut document: toml::Spanned<toml::de::DeTable<'_>>,\n) -> toml::Spanned<toml::de::DeTable<'static>> {\n    document.get_mut().make_owned();\n    // SAFETY: `DeTable::make_owned` ensures no borrows remain and the lifetime does not affect\n    // layout\n    unsafe {\n        std::mem::transmute::<\n            toml::Spanned<toml::de::DeTable<'_>>,\n            toml::Spanned<toml::de::DeTable<'static>>,\n        >(document)\n    }\n}\n\n#[tracing::instrument(skip_all)]\nfn read_toml_string(path: &Path, is_embedded: bool, gctx: &GlobalContext) -> CargoResult<String> {\n    let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?;\n    if is_embedded {\n        if !gctx.cli_unstable().script {\n            anyhow::bail!(\"parsing `{}` requires `-Zscript`\", path.display());\n        }\n        contents = embedded::expand_manifest(&contents)\n            .map_err(|e| emit_frontmatter_diagnostic(e, &contents, path, gctx))?;\n    }\n    Ok(contents)\n}\n\n#[tracing::instrument(skip_all)]\nfn parse_document(contents: &str) -> Result<toml::Spanned<toml::de::DeTable<'_>>, toml::de::Error> {\n    toml::de::DeTable::parse(&contents)\n}\n\n#[tracing::instrument(skip_all)]\nfn deserialize_toml(\n    document: &toml::Spanned<toml::de::DeTable<'_>>,\n) -> Result<manifest::TomlManifest, toml::de::Error> {\n    let mut unused = BTreeSet::new();\n    let deserializer = toml::de::Deserializer::from(document.clone());","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/parser/mod.rs#L161-L197","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\ncargo run ./script.rs\n\n# after (nightly)\ncargo +nightly run -Zscript ./script.rs","handlingStrategy":"try-catch","validationCode":"fn check_script_feature_enabled(gctx: &GlobalContext) -> bool {\n    gctx.cli_unstable().script\n}","typeGuard":null,"tryCatchPattern":"match parse_manifest(path, gctx) {\n    Ok(m) => m,\n    Err(e) if e.to_string().contains(\"requires `-Zscript`\") => {\n        eprintln!(\"Re-run with nightly cargo and -Zscript for embedded manifests\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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."],"tags":["cargo","unstable","script","embedded-manifest","nightly"],"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"}