slint-ui/slint · error
Invalid Cargo.toml -- cannot find workspace package section…
Error message
Invalid Cargo.toml -- cannot find workspace package section in workspace file
What it means
CargoToml::package() found a [workspace] table but no [workspace.package] table (or it is not a TOML table) in the workspace root manifest, so the workspace-level package settings used for inheritance cannot be read. The manifest is therefore considered invalid for the purposes of the xtask license/version consistency check.
Solutions
- Add a [workspace.package] section with the shared fields (version, license, etc.) to the workspace root Cargo.toml.
- Verify the [workspace] table parses as a table and contains package = { ... }; fix any malformed TOML.
- If this manifest is a virtual workspace with no intended shared package config, exclude it from this check or handle it before calling package().
- Ensure the check runs against the correct manifest path; a member manifest misdetected as a root would trigger this.
Example fix
// before: workspace root missing inheritance metadata [workspace] members = ["crates/foo"] // after [workspace] members = ["crates/foo"] [workspace.package] version = "1.0.0" license = "GPL-3.0-only OR MIT"
Defensive patterns
Strategy: validation
Validate before calling
fn has_workspace_package(doc: &toml_edit::DocumentMut) -> bool {
doc.as_table().get("workspace")
.and_then(|w| w.as_table())
.and_then(|w| w.get("package"))
.and_then(|p| p.as_table())
.is_some()
} Type guard
fn workspace_package_table(doc: &toml_edit::DocumentMut) -> Option<&toml_edit::Table> {
doc.as_table().get("workspace")?.as_table()?.get("package")?.as_table()
} Try / catch
match cargo_toml.package() {
Ok(pkg) => check_fields(pkg),
Err(e) if e.to_string().contains("workspace package section") => {
anyhow::bail!("{}: add a [workspace.package] section with shared version/license", cargo_toml.path.display())
}
Err(e) => return Err(e),
} Prevention
- Every workspace root must define [workspace.package] with version and license.
- Validate workspace manifests in CI before running the consistency check.
- Don't delete [workspace.package] when restructuring; members depend on it for inheritance.
- Distinguish virtual workspaces (no package inheritance config) and skip or configure them explicitly.
When it happens
Trigger: package() is called (from check_and_fix_package_string_field or published) on a workspace root Cargo.toml that lacks a workspace.package section, or whose [workspace] table has no parseable package sub-table.
Common situations: A workspace root created without workspace.package metadata (no shared version/license fields); a malformed edit removed [workspace.package]; a manifest with an empty [workspace] table (e.g. a virtual workspace without package inheritance config) is checked.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Incorrect .workspace found: expected true, found false
- Invalid Cargo.toml -- cannot find package section
- Not a workspace, can not extract version info.
- Using workspace .workspace = true in workspace
- cargo failed
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/9aa14d79e03a1e48.
Report an issue: GitHub.
Appendix: source
Thrown at xtask/src/license_headers_check.rs:815
.unwrap()
.get("package")
.unwrap()
.get("version")
.unwrap()
.as_str()
.unwrap())
}
}
fn package(&self) -> Result<&toml_edit::Table> {
if self.is_workspace() {
self.doc
.as_table()
.get("workspace")
.and_then(|w| w.as_table())
.and_then(|w| w.get("package"))
.and_then(|p| p.as_table())
.ok_or_else(|| anyhow!("Invalid Cargo.toml -- cannot find workspace package section in workspace file"))
} else {
self.doc
.as_table()
.get("package")
.and_then(|p| p.as_table())
.ok_or_else(|| anyhow!("Invalid Cargo.toml -- cannot find package section"))
}
}
fn dependencies(&self, dep_type: &str) -> Vec<(String, CargoDependency)> {
let table = if self.is_workspace() {
self.doc
.as_table()
.get("workspace")
.and_then(|w| w.as_table())
.and_then(|w| w.get(dep_type))
.and_then(|d| d.as_table())
} else {View on GitHub (pinned to 3a7e700487)