rust-lang/cargo · error · anyhow::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 of manifest parsing in src/workspace/parser/mod.rs:138. After deserialization, cargo dispatches on whether a `[package]` table (→ real manifest) or a `[workspace]` table (→ virtual manifest) exists. If neither is present the file is not a valid Cargo manifest and parsing aborts.

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 0e07a15537)

Solutions

  1. Add a `[package]` section with at least `name` and `version`, or a `[workspace]` section if this is a virtual root.
  2. Verify the file path you passed is a real `Cargo.toml`.
  3. If editing, restore the deleted `[package]`/`[workspace]` header.

Example fix

# before
# (empty file, or only [dependencies])
[dependencies]
serde = "1"
# after
[package]
name = "mycrate"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = "1"
Defensive patterns

Strategy: validation

Validate before calling

let has_pkg = doc.as_table().get("package").and_then(|i| i.as_table_like()).is_some();
let has_ws  = doc.as_table().get("workspace").and_then(|i| i.as_table_like()).is_some();
if !has_pkg && !has_ws {
    return Err("manifest needs [package] or [workspace]".into());
}

Prevention

When it happens

Trigger: An empty `Cargo.toml`, one containing only `[dependencies]`, or a TOML file that is valid TOML but has neither section. `normalized_toml.package.is_none() && normalized_toml.workspace.is_none()`.

Common situations: Pointing cargo at the wrong file (`Cargo.lock`, a `*.rs` script without frontmatter, a `config.toml`); a freshly created empty crate dir; a manifest accidentally truncated to comments only.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/617f9edef4b6b245.json. Report an issue: GitHub.