rust-lang/cargo · error · anyhow::Error
{fields} {are} not allowed in embedded manifests
Error message
{fields} {are} not allowed in embedded manifests What it means
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).
Source
Thrown at src/workspace/parser/mod.rs:1503
("`package.autobins`", autobins.is_some()),
("`package.autoexamples`", autoexamples.is_some()),
("`package.autotests`", autotests.is_some()),
("`package.autobenches`", autobenches.is_some()),
("`package.default-run`", default_run.is_some()),
]);
}
let invalid_fields = invalid_fields
.into_iter()
.filter_map(|(name, invalid)| invalid.then_some(name))
.collect::<Vec<_>>();
if !invalid_fields.is_empty() {
let fields = invalid_fields.join(", ");
let are = if invalid_fields.len() == 1 {
"is"
} else {
"are"
};
anyhow::bail!("{fields} {are} not allowed in embedded manifests")
}
}
let resolve_behavior = match (
normalized_package.resolver.as_ref(),
normalized_toml
.workspace
.as_ref()
.and_then(|ws| ws.resolver.as_ref()),
) {
(None, None) => None,
(Some(s), None) | (None, Some(s)) => Some(ResolveBehavior::from_manifest(s)?),
(Some(_), Some(_)) => {
bail!("cannot specify `resolver` field in both `[workspace]` and `[package]`")
}
};
// If we have no lib at all, use the inferred lib, if available.View on GitHub (pinned to 0e07a15537)
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`.
Example fix
# before (script frontmatter) [package] name = "demo" links = "foo" # after [package] name = "demo"
Defensive patterns
Strategy: validation
Validate before calling
const FORBIDDEN: &[&str] = &["workspace","build","metabuild","links","autolib",
"autobins","autoexamples","autotests","autobenches","default-run"];
if is_embedded {
if let Some(pkg) = doc.get("package").and_then(|i| i.as_table_like()) {
for f in FORBIDDEN {
if pkg.contains_key(*f) { return Err(format!("{f} not allowed in embedded manifest")); }
}
}
} Prevention
- Keep embedded-manifest `[package]` minimal (name + version + edition).
- Convert to a real crate if you need links/build/workspace features.
When it happens
Trigger: A `.rs` cargo script whose frontmatter `[package]` table includes e.g. `links = "foo"`, `build = "build.rs"`, `default-run = "x"`, or `autobins = false`.
Common situations: Trying to reuse a regular crate's `[package]` table inside a script file; LLM-generated frontmatter; misunderstanding embedded-manifest limits.
Related errors
- parsing `{}` requires `-Zscript`
- the manifest-path must be a path to a Cargo.toml or script f
- the manifest-path must be a path to a Cargo.toml file: `{}`
- embedded manifest `{}` requires `-Zscript`
- parsing `{}` requires `-Zscript`
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/51fe6b79aecc5d32.json.
Report an issue: GitHub.