{"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":"validation","errorClass":"anyhow::Error","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/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/mod.rs#L1485-L1521","documentation":"Thrown at src/workspace/parser/mod.rs:1503 when parsing an embedded (single-file) manifest. Embedded manifests are restricted and cannot carry package fields that imply target discovery, native linking, or workspace membership: `workspace`, `build`, `metabuild`, `links`, `autolib`, `autobins`, `autoexamples`, `autotests`, `autobenches`, and `default-run`. Any present field is collected and reported (with correct is/are agreement).","triggerScenarios":"A `.rs` cargo script whose frontmatter `[package]` table includes e.g. `links = \"foo\"`, `build = \"build.rs\"`, `default-run = \"x\"`, or `autobins = false`.","commonSituations":"Trying to reuse a regular crate's `[package]` table inside a script file; LLM-generated frontmatter; misunderstanding embedded-manifest limits.","solutions":["Remove the disallowed field(s) from the script's frontmatter `[package]` table.","If you need `links`/`build`/workspace features, convert the script into a normal multi-file crate with a `Cargo.toml`."],"exampleFix":"# before (script frontmatter)\n[package]\nname = \"demo\"\nlinks = \"foo\"\n# after\n[package]\nname = \"demo\"","handlingStrategy":"validation","validationCode":"const FORBIDDEN: &[&str] = &[\"workspace\",\"build\",\"metabuild\",\"links\",\"autolib\",\n    \"autobins\",\"autoexamples\",\"autotests\",\"autobenches\",\"default-run\"];\nif is_embedded {\n    if let Some(pkg) = doc.get(\"package\").and_then(|i| i.as_table_like()) {\n        for f in FORBIDDEN {\n            if pkg.contains_key(*f) { return Err(format!(\"{f} not allowed in embedded manifest\")); }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep embedded-manifest `[package]` minimal (name + version + edition).","Convert to a real crate if you need links/build/workspace features."],"tags":["embedded-manifest","manifest","script"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}