Skip to content

Conversation

andrewgazelka
Copy link

Adds a new cargo lint that enforces using workspace = true for dependencies that are defined in [workspace.dependencies].

What it does

Checks that dependencies defined in [workspace.dependencies] are referenced with workspace = true in package dependency declarations instead of specifying version, git, or path information directly.

Why is this useful

When using workspace dependencies, all version information should be centralized in the workspace's Cargo.toml to ensure consistency across all crates in the workspace. Specifying version information in individual packages defeats this purpose and can lead to version mismatches.

Example

# In workspace Cargo.toml
[workspace.dependencies]
serde = "1.0"

# In package Cargo.toml (bad)
[dependencies]
serde = "1.0"

Use instead:

# In workspace Cargo.toml
[workspace.dependencies]
serde = "1.0"

# In package Cargo.toml (good)
[dependencies]
serde = { workspace = true }
# or with features
serde = { workspace = true, features = ["derive"] }

The lint checks [dependencies], [dev-dependencies], and [build-dependencies] sections.

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.

1 participant