rust-lang/cargo · error
manifest is missing either a `[package]` or a `[workspace]`
Error message
manifest is missing either a `[package]` or a `[workspace]`
What it means
Thrown at the top level of manifest parsing after deserialization: if the TomlManifest has neither a [package] (nor [project]) section nor a [workspace] section, it is structurally invalid. Every Cargo.toml must define at least one of these. The error is wrapped with the file path via 'failed to parse manifest at ...'.
Solutions
- Add a [package] section with at minimum name, version, and edition to the manifest.
- If this is a virtual workspace root, add a [workspace] section with members = [...].
- Verify you are pointing cargo at the correct file (not a config or lockfile).
Example fix
# before [dependencies] serde = "1.0" # after [package] name = "my-crate" version = "0.1.0" edition = "2021" [dependencies] serde = "1.0"
Defensive patterns
Strategy: validation
Validate before calling
fn manifest_has_package_or_workspace(toml: &str) -> Result<(), String> {
let parsed: toml::Value = toml::from_str(toml).map_err(|e| e.to_string())?;
let has_pkg = parsed.get("package").is_some() || parsed.get("project").is_some();
let has_ws = parsed.get("workspace").is_some();
if !(has_pkg || has_ws) {
return Err("manifest must contain [package] or [workspace]".into());
}
Ok(())
} Type guard
fn is_valid_manifest_top_level(toml: &toml::Value) -> bool {
toml.get("package").is_some() || toml.get("project").is_some() || toml.get("workspace").is_some()
} Prevention
- Ensure every Cargo.toml has a [package] or [workspace] header before running cargo.
- Use project templates that always include a [package] section.
- Validate generated manifests with `cargo metadata` in CI.
When it happens
Trigger: Calling the manifest parser on a Cargo.toml that contains only e.g. [dependencies] with no [package] or [workspace]. Also triggered by an empty file or a file with only a [lib]/[[bin]] target section.
Common situations: A developer creates a new Cargo.toml by hand and forgets the [package] header. A generated manifest template is incomplete. A file intended as a .cargo/config.toml is accidentally named Cargo.toml. A workspace root Cargo.toml missing the [workspace] table.
Related errors
- dependency ( ) specified without providing a local path…
- `lints. . ` is not a valid lint name
- `lints. . ` is not valid lint name; try `lints. .
- `[project]` is not supported as of the 2024 Edition, please…
- replacements must specify a version to replace, but
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/617f9edef4b6b245.
Report an issue: GitHub.
Appendix: source
Thrown at src/workspace/parser/mod.rs:138
.map(EitherManifest::Real)
} else if normalized_toml.workspace.is_some() {
assert!(!is_embedded);
to_virtual_manifest(
Some(contents),
Some(document),
original_toml,
normalized_toml,
features,
workspace_config,
source_id,
path,
gctx,
&mut warnings,
&mut errors,
)
.map(EitherManifest::Virtual)
} else {
anyhow::bail!("manifest is missing either a `[package]` or a `[workspace]`")
}
})()
.map_err(|err| {
ManifestError::new(
err.context(format!("failed to parse manifest at `{}`", path.display())),
path.into(),
)
})?;
for warning in warnings {
manifest.warnings_mut().add_warning(warning);
}
for error in errors {
manifest.warnings_mut().add_critical_warning(error);
}
Ok(manifest)
}View on GitHub (pinned to 98a09e7e7d)