{"id":"df99fa51161a3d3d","repo":"rust-lang/cargo","slug":"parsing-requires-zscript","errorCode":null,"errorMessage":"parsing `{}` requires `-Zscript`","messagePattern":"parsing `(.+?)` requires `-Zscript`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/mod.rs","lineNumber":814,"sourceCode":"\n/// 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.\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":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/mod.rs#L796-L832","documentation":"When compiling a unit whose manifest is 'embedded' (a single-file package, e.g. a .rs file with an embedded `cargo` manifest / frontmatter), prepare_rustc (mod.rs:812-818) requires the nightly-only `-Zscript` feature to be enabled on the Cargo invocation. Without it, Cargo bails with 'parsing `<path>` requires `-Zscript`'. The script feature unlocks single-file packages and passes extra rustc crate-attrs for frontmatter parsing.","triggerScenarios":"Running `cargo build`/`cargo run` against a `.rs` file (or a package detected as embedded) without passing `-Zscript`. prepare_rustc checks `gctx.cli_unstable().script` and bails when false.","commonSituations":"Trying the single-file package RFC on stable Cargo; forgetting the `-Zscript` flag; switching toolchains away from nightly where unstable flags are allowed.","solutions":["Use a nightly toolchain: `cargo +nightly build -Zscript`.","Ensure `nightly_features_allowed` is true (run on the `nightly` or `dev` channel).","If you did not intend a single-file package, convert it to a normal Cargo project (Cargo.toml + src/main.rs) so it is no longer detected as embedded."],"exampleFix":"# before\ncargo build script.rs\n# after\ncargo +nightly build -Zscript script.rs","handlingStrategy":"validation","validationCode":"# Before building a single-file package, verify nightly + flag:\nif cargo +nightly -Zscript --version >/dev/null 2>&1; then\n  cargo +nightly build -Zscript script.rs\nelse\n  echo \"requires nightly cargo with -Zscript\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a nightly toolchain in rust-toolchain.toml for projects using single-file packages.","Document the -Zscript requirement in the project README.","Use a conventional Cargo.toml layout if stable support is needed."],"tags":["script","unstable","nightly","embedded-manifest","rustc"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}