rust-lang/cargo · error

parsing ` ` requires `-Zscript

Error message

parsing `{}` requires `-Zscript`

What it means

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.

Solutions

  1. Use a nightly toolchain: `rustup override set nightly` then `cargo +nightly run -Zscript script.rs`.
  2. Set `RUSTC_BOOTSTRAP=1` as a last-resort escape hatch on stable (not recommended for production).
  3. Move the embedded manifest into a regular `Cargo.toml` if you don't need single-file mode.

Example fix

// before
cargo run ./my_script.rs

// after
rustup override set nightly
cargo run -Z script ./my_script.rs
Defensive patterns

Strategy: validation

Validate before calling

fn script_feature_enabled(gctx: &GlobalContext) -> bool {
    gctx.cli_unstable().script
}

Type guard

fn is_embedded_manifest(path: &Path) -> bool {
    path.extension().and_then(|e| e.to_str()) == Some("rs") && std::fs::read_to_string(path).map(|s| s.contains("```cargo")).unwrap_or(false)
}

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: Adopting RFC 3506 cargo scripts on stable; CI pinned to stable; toolchain override unset so stable is used by default.

Related errors


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

Appendix: source

Thrown at src/compiler/mod.rs:838

/// Prepares flags and environments we can compute for a `rustc` invocation
/// before the job queue starts compiling any unit.
///
/// This builds a static view of the invocation. Flags depending on the
/// completion of other units will be added later in runtime, such as flags
/// from build scripts.
#[tracing::instrument(skip_all)]
fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult<ProcessBuilder> {
    let gctx = build_runner.bcx.gctx;
    let is_primary = build_runner.is_primary_package(unit);
    let is_workspace = build_runner.bcx.ws.is_member(&unit.pkg);

    let mut base = build_runner
        .compilation
        .rustc_process(unit, is_primary, is_workspace)?;
    build_base_args(build_runner, &mut base, unit)?;
    if unit.pkg.manifest().is_embedded() {
        if !gctx.cli_unstable().script {
            anyhow::bail!(
                "parsing `{}` requires `-Zscript`",
                unit.pkg.manifest_path().display()
            );
        }
        base.arg("-Z").arg("crate-attr=feature(frontmatter)");
        base.arg("-Z").arg("crate-attr=allow(unused_features)");
    }

    base.inherit_jobserver(&build_runner.jobserver);
    build_deps_args(&mut base, build_runner, unit)?;
    add_cap_lints(build_runner.bcx, unit, &mut base);
    if let Some(args) = build_runner.bcx.extra_args_for(unit) {
        base.args(args);
    }
    base.args(&unit.rustflags);
    if gctx.cli_unstable().binary_dep_depinfo {
        base.arg("-Z").arg("binary-dep-depinfo");
    }

View on GitHub (pinned to 98a09e7e7d)