{"id":"fa464b7d46b1d42f","repo":"rust-lang/cargo","slug":"embedded-manifest-requires-zscript","errorCode":null,"errorMessage":"embedded manifest `{}` requires `-Zscript`","messagePattern":"embedded manifest `(.+?)` requires `-Zscript`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":1082,"sourceCode":"            anyhow::bail!(\n                \"manifest path `{}` is a directory but expected a file{suggested_path}\",\n                manifest_path.display()\n            )\n        } else if !path.ends_with(\"Cargo.toml\") && !crate::workspace::parser::is_embedded(&path) {\n            if gctx.cli_unstable().script {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml or script file: `{}`\",\n                    path.display()\n                )\n            } else {\n                anyhow::bail!(\n                    \"the manifest-path must be a path to a Cargo.toml file: `{}`\",\n                    path.display()\n                )\n            }\n        }\n        if crate::workspace::parser::is_embedded(&path) && !gctx.cli_unstable().script {\n            anyhow::bail!(\"embedded manifest `{}` requires `-Zscript`\", path.display())\n        }\n        Ok(path)\n    } else {\n        find_root_manifest_for_wd(gctx.cwd())\n    }\n}\n\npub fn get_registry_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {\n    let gctx = new_gctx_for_completions()?;\n\n    if let Ok(Some(registries)) =\n        gctx.get::<Option<HashMap<String, HashMap<String, String>>>>(\"registries\")\n    {\n        Ok(registries\n            .keys()\n            .map(|name| clap_complete::CompletionCandidate::new(name.to_owned()))\n            .collect())\n    } else {","sourceCodeStart":1064,"sourceCodeEnd":1100,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L1064-L1100","documentation":"root_manifest detects via workspace::parser::is_embedded that the given path is an embedded manifest (a `.rs` file with a leading `//! ```cargo` block) but the `-Zscript` unstable flag is not enabled. Embedded manifests are part of cargo script (RFC 3424) and require the nightly `-Zscript` flag.","triggerScenarios":"Passing an embedded-manifest `.rs` script file as `--manifest-path` on a cargo build that was not launched with `-Zscript` (e.g. stable cargo, or nightly without the flag).","commonSituations":"Running a cargo script with stable cargo; nightly cargo invoked without `-Zscript`; a wrapper/IDE that passes the script path but not the unstable flag.","solutions":["Re-run with `-Zscript` on a nightly toolchain: `cargo +nightly run -Zscript --manifest-path script.rs`.","If you did not mean to use a script, point `--manifest-path` at a real `Cargo.toml`.","Configure your IDE/wrapper to pass `-Zscript` when invoking on script files."],"exampleFix":"# before\ncargo run --manifest-path script.rs\n\n# after\ncargo +nightly run -Zscript --manifest-path script.rs","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn require_script_flag_if_embedded(p: &Path, script_enabled: bool) -> Result<(), anyhow::Error> {\n    if cargo::workspace::parser::is_embedded(p) && !script_enabled {\n        anyhow::bail!(\"embedded manifest requires nightly cargo with -Zscript\");\n    }\n    Ok(())\n}\n// script_enabled = gctx.cli_unstable().script","typeGuard":"fn needs_script_flag(p: &std::path::Path) -> bool {\n    cargo::workspace::parser::is_embedded(p)\n}","tryCatchPattern":"match root_manifest(Some(path), gctx) {\n    Err(e) if e.to_string().contains(\"requires `-Zscript`\") => {\n        eprintln!(\"re-run with: cargo +nightly run -Zscript --manifest-path {path}\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Reserve embedded `.rs` manifests for nightly + `-Zscript`.","Configure IDE/wrappers to add `-Zscript` when launching script files."],"tags":["cli","manifest","script","unstable","path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}