Skip to content

Accept workspace-inherited [package] fields in Cargo.toml - #90

Merged
andrew merged 1 commit into
mainfrom
cargo-workspace-inheritable-fields
Sep 5, 2026
Merged

Accept workspace-inherited [package] fields in Cargo.toml#90
andrew merged 1 commit into
mainfrom
cargo-workspace-inheritable-fields

Conversation

@andrew

@andrew andrew commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Cargo workspace inheritance (RFC 2906, stable since Rust 1.64) lets inheritable [package] fields be written as field.workspace = true instead of a literal. Version, License, and LicenseFile were decoded as string, so toml.Decode errored on the type mismatch and the whole file came back as a ParseError, dropping dependencies too.

inheritableString implements UnmarshalTOML accepting either a string or a table, yielding empty for the table form since the workspace root value is not resolvable from a single file. Name is not inheritable per the Cargo spec and stays a plain string.

The string path is one type assertion with no allocation. Verified against rust-lang/cargo at a07c49a via git-pkgs/licenses: 19 workspace-member Cargo.toml parse errors clear with no wall-time or RSS change.

Cargo workspace inheritance (RFC 2906, Rust 1.64+) lets [package]
version, license, and license-file be written as {workspace = true}
instead of a string. Decoding those into a string field made
toml.Decode error on the whole file, so dependencies were lost too.

Add an inheritableString type whose UnmarshalTOML accepts either form,
yielding the zero value for the table form since the workspace root is
not visible from a single-file parse. Name is not inheritable and
stays a plain string.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new UnmarshalTOML implementation is currently too permissive (silently accepting any non-string type), which can mask real manifest schema errors.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the Cargo.toml manifest parser to tolerate Cargo workspace-inherited [package] fields (RFC 2906) so that decoding doesn’t fail (and drop dependency extraction) when fields like version/license are provided via the { workspace = true } form.

Changes:

  • Add inheritableString with UnmarshalTOML to accept either a literal string or the workspace-inheritance table form for selected [package] fields.
  • Update cargoTomlParser.Parse to convert those custom-typed fields back into plain strings in core.Result.
  • Add a unit test covering workspace-inherited fields and ensuring dependencies are still parsed.
File summaries
File Description
internal/cargo/cargo.go Introduces a TOML-unmarshal helper type for inheritable [package] fields and wires it into parse output.
internal/cargo/cargo_test.go Adds coverage for workspace-inherited [package] fields and ensures dependency parsing remains intact.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/cargo/cargo.go
Comment on lines +28 to +32
func (s *inheritableString) UnmarshalTOML(v any) error {
if str, ok := v.(string); ok {
*s = inheritableString(str)
}
return nil
@andrew
andrew merged commit 16f1b1b into main Sep 5, 2026
6 checks passed
@andrew
andrew deleted the cargo-workspace-inheritable-fields branch September 5, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants