{"record":{"id":"51fe6b79aecc5d32","repo":"rust-lang/cargo","slug":"fields-are-not-allowed-in-embedded-manifests","errorCode":null,"errorMessage":"{fields} {are} not allowed in embedded manifests","messagePattern":"(.+?) (.+?) not allowed in embedded manifests","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/mod.rs","lineNumber":1503,"sourceCode":"                (\"`package.autobins`\", autobins.is_some()),\n                (\"`package.autoexamples`\", autoexamples.is_some()),\n                (\"`package.autotests`\", autotests.is_some()),\n                (\"`package.autobenches`\", autobenches.is_some()),\n                (\"`package.default-run`\", default_run.is_some()),\n            ]);\n        }\n        let invalid_fields = invalid_fields\n            .into_iter()\n            .filter_map(|(name, invalid)| invalid.then_some(name))\n            .collect::<Vec<_>>();\n        if !invalid_fields.is_empty() {\n            let fields = invalid_fields.join(\", \");\n            let are = if invalid_fields.len() == 1 {\n                \"is\"\n            } else {\n                \"are\"\n            };\n            anyhow::bail!(\"{fields} {are} not allowed in embedded manifests\")\n        }\n    }\n\n    let resolve_behavior = match (\n        normalized_package.resolver.as_ref(),\n        normalized_toml\n            .workspace\n            .as_ref()\n            .and_then(|ws| ws.resolver.as_ref()),\n    ) {\n        (None, None) => None,\n        (Some(s), None) | (None, Some(s)) => Some(ResolveBehavior::from_manifest(s)?),\n        (Some(_), Some(_)) => {\n            bail!(\"cannot specify `resolver` field in both `[workspace]` and `[package]`\")\n        }\n    };\n\n    // If we have no lib at all, use the inferred lib, if available.","sourceCodeStart":1485,"sourceCodeEnd":1521,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/parser/mod.rs#L1485-L1521","documentation":"Thrown when validating an embedded (single-file script) manifest that contains package fields forbidden in embedded contexts. The forbidden fields include package.workspace, package.build, package.metabuild, package.links, package.autolib/autobins/autoexamples/autotests/autobenches, and package.default-run. Embedded scripts have constrained semantics (no custom build, no auto-discovery), so these fields are collected into invalid_fields and reported with proper is/are agreement.","triggerScenarios":"A single-file cargo script (.rs with frontmatter) whose frontmatter package table includes e.g. build = \"build.rs\" or default-run = \"x\". During to_real_manifest the is_embedded branch builds the invalid_fields list and bails if non-empty.","commonSituations":"A developer copies fields from a regular Cargo.toml into a script's frontmatter. Using workspace inheritance inside an embedded script. Specifying a custom build script in a single-file context where it cannot apply.","solutions":["Remove all forbidden fields from the embedded manifest's frontmatter package table.","If you need build scripts, autodiscovery, or workspace links, use a traditional multi-file Cargo project instead of an embedded script.","Move default-run and workspace declarations to a real Cargo.toml [package] section."],"exampleFix":"// before (script.rs frontmatter)\n//! ```cargo\n//! [package]\n//! name = \"x\"\n//! build = \"build.rs\"\n//! ```\n\n// after\n//! ```cargo\n//! [package]\n//! name = \"x\"\n//! ```","handlingStrategy":"validation","validationCode":"const FORBIDDEN_EMBEDDED: &[&str] = &[\n    \"workspace\",\"build\",\"metabuild\",\"links\",\"autolib\",\n    \"autobins\",\"autoexamples\",\"autotests\",\"autobenches\",\"default-run\",\n];\nfn check_embedded_package(pkg: &toml::Value) -> Result<(), String> {\n    let bad: Vec<&&str> = FORBIDDEN_EMBEDDED.iter()\n        .filter(|k| pkg.get(**k).is_some())\n        .collect();\n    if bad.is_empty() { Ok(()) } else { Err(format!(\"forbidden in embedded manifest: {}\", bad.join(\", \"))) }\n}","typeGuard":"fn embedded_pkg_has_forbidden_fields(pkg: &toml::value::Table) -> bool {\n    [\"workspace\",\"build\",\"metabuild\",\"links\",\"autolib\",\"autobins\",\"autoexamples\",\"autotests\",\"autobenches\",\"default-run\"]\n        .iter().any(|k| pkg.contains_key(*k))\n}","tryCatchPattern":null,"preventionTips":["Keep embedded script frontmatter minimal: name, version, edition, dependencies only.","If you need build scripts or auto-discovery, use a traditional Cargo project.","Validate frontmatter against the allowed field list before running."],"tags":["cargo","embedded-manifest","script","package","unsupported-field"],"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"}