Skip to content

Commit

Permalink
Auto merge of #11565 - Muscraft:rework-toml-dependency, r=weihanglo
Browse files Browse the repository at this point in the history
refactor(toml): Move `TomlWorkspaceDependency` out of `TomlDependency`

**This should not be merged until after #11409**

In #11523 it was noted that you could use `{}.workspace = true` in `[patch.{}]`, but it would cause a panic. This panic was caused by an oversight on my part when implementing [workspace inheritance](https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md). Before this PR any field that had the type `TomlDependency` could specify `{}.workspace = true` and `cargo` would allow it to be a `TomlWorkspaceDependency`. While it could be `TomlWorkspaceDependency` it would never be resolved since only:

> Dependencies in the `[dependencies]`, `[dev-dependencies]`, [`build-dependencies]`, and `[target."...".dependencies]` sections will support the ability to reference the `[workspace.dependencies]` definition of dependencies.[^1]

This PR makes it so that only those fields can pull from `[workspace.dependencies]`, while still sharing `TomlDependency` everywhere it is needed. It does this by making `MaybeWorkspace` generic over both `Defined` and `Workspace`, then moving `TomlWorkspaceDependency` out of `TomlDependency` and into a `MaybeWorkspace` that the correct fields can use.

[^1]: [rfc2906-new-dependency-directives](https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#new-dependency-directives)

Closes: #11523
  • Loading branch information
bors committed Jan 25, 2023
2 parents 4a2ebfb + 712b327 commit 2ccd950
Show file tree
Hide file tree
Showing 2 changed files with 287 additions and 269 deletions.
Loading

0 comments on commit 2ccd950

Please sign in to comment.