Accept workspace-inherited [package] fields in Cargo.toml - #90
Merged
Conversation
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.
There was a problem hiding this comment.
🟡 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
inheritableStringwithUnmarshalTOMLto accept either a literal string or the workspace-inheritance table form for selected[package]fields. - Update
cargoTomlParser.Parseto convert those custom-typed fields back into plain strings incore.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 on lines
+28
to
+32
| func (s *inheritableString) UnmarshalTOML(v any) error { | ||
| if str, ok := v.(string); ok { | ||
| *s = inheritableString(str) | ||
| } | ||
| return nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cargo workspace inheritance (RFC 2906, stable since Rust 1.64) lets inheritable
[package]fields be written asfield.workspace = trueinstead of a literal.Version,License, andLicenseFilewere decoded asstring, sotoml.Decodeerrored on the type mismatch and the whole file came back as aParseError, dropping dependencies too.inheritableStringimplementsUnmarshalTOMLaccepting either a string or a table, yielding empty for the table form since the workspace root value is not resolvable from a single file.Nameis 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/cargoata07c49aviagit-pkgs/licenses: 19 workspace-memberCargo.tomlparse errors clear with no wall-time or RSS change.