{"record":{"id":"df99fa51161a3d3d","repo":"rust-lang/cargo","slug":"parsing-requires-zscript","errorCode":null,"errorMessage":"parsing `{}` requires `-Zscript`","messagePattern":"parsing `(.+?)` requires `-Zscript`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/mod.rs","lineNumber":838,"sourceCode":"/// Prepares flags and environments we can compute for a `rustc` invocation\n/// before the job queue starts compiling any unit.\n///\n/// This builds a static view of the invocation. Flags depending on the\n/// completion of other units will be added later in runtime, such as flags\n/// from build scripts.\n#[tracing::instrument(skip_all)]\nfn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<ProcessBuilder> {\n    let gctx = build_runner.bcx.gctx;\n    let is_primary = build_runner.is_primary_package(unit);\n    let is_workspace = build_runner.bcx.ws.is_member(&unit.pkg);\n\n    let mut base = build_runner\n        .compilation\n        .rustc_process(unit, is_primary, is_workspace)?;\n    build_base_args(build_runner, &mut base, unit)?;\n    if unit.pkg.manifest().is_embedded() {\n        if !gctx.cli_unstable().script {\n            anyhow::bail!(\n                \"parsing `{}` requires `-Zscript`\",\n                unit.pkg.manifest_path().display()\n            );\n        }\n        base.arg(\"-Z\").arg(\"crate-attr=feature(frontmatter)\");\n        base.arg(\"-Z\").arg(\"crate-attr=allow(unused_features)\");\n    }\n\n    base.inherit_jobserver(&build_runner.jobserver);\n    build_deps_args(&mut base, build_runner, unit)?;\n    add_cap_lints(build_runner.bcx, unit, &mut base);\n    if let Some(args) = build_runner.bcx.extra_args_for(unit) {\n        base.args(args);\n    }\n    base.args(&unit.rustflags);\n    if gctx.cli_unstable().binary_dep_depinfo {\n        base.arg(\"-Z\").arg(\"binary-dep-depinfo\");\n    }","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/compiler/mod.rs#L820-L856","documentation":"The package's manifest is embedded (a single-file `cargo-script` / `daydream`-style `Cargo.toml` embedded in a `.rs` file via frontmatter) but the `-Zscript` unstable feature is not enabled. `prepare_rustc` checks `manifest().is_embedded()` and `gctx.cli_unstable().script` before adding the `crate-attr=feature(frontmatter)` flags to rustc.","triggerScenarios":"Running a single-file Rust script (e.g. `cargo run script.rs` with embedded manifest) without the `script` unstable flag; `RUSTC_BOOTSTRAP` not set and no nightly override.","commonSituations":"Adopting RFC 3506 cargo scripts on stable; CI pinned to stable; toolchain override unset so stable is used by default.","solutions":["Use a nightly toolchain: `rustup override set nightly` then `cargo +nightly run -Zscript script.rs`.","Set `RUSTC_BOOTSTRAP=1` as a last-resort escape hatch on stable (not recommended for production).","Move the embedded manifest into a regular `Cargo.toml` if you don't need single-file mode."],"exampleFix":"// before\ncargo run ./my_script.rs\n\n// after\nrustup override set nightly\ncargo run -Z script ./my_script.rs","handlingStrategy":"validation","validationCode":"fn script_feature_enabled(gctx: &GlobalContext) -> bool {\n    gctx.cli_unstable().script\n}","typeGuard":"fn is_embedded_manifest(path: &Path) -> bool {\n    path.extension().and_then(|e| e.to_str()) == Some(\"rs\") && std::fs::read_to_string(path).map(|s| s.contains(\"```cargo\")).unwrap_or(false)\n}","tryCatchPattern":"null","preventionTips":["Pin nightly via `rust-toolchain.toml` for projects using cargo scripts.","Document the `-Zscript` requirement in the README.","CI: assert `cargo +nightly -Zscript --version` succeeds before building."],"tags":["cargo","unstable","script","toolchain","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"}