rust-lang / rust-lang/rust-clippy

Workspace dependencies

Open
#10,306 18 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint T-cargo
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

I'm not sure if it is a Clippy responsibility, but I think it would be nice to suggest to use "workspace dependencies" if some library is used in multiple workspace crates.

Perhaps the opposite changes can be suggested if a dependency is used only once or less than some threshold value, though this logic should probably be a separate lint. Ideally both values should be configurable.

Lint Name

workspace_dependencies

Category

pedantic

Advantage
  • It is much more convenient to change the dependency version in one place.
Drawbacks

The only disadvantage I can see is that such lint can be noisy for small workspaces, so it probably should be disabled by default.

Example

I don't think this example is needed, but nevertheless:

# [PROJECT_DIR]/Cargo.toml
[workspace]
members = ["foo", "bar"]

# [PROJECT_DIR]/foo/Cargo.toml
[package]
name = "foo"

[dependencies]
rand = "0.8.5"

# [PROJECT_DIR]/bar/Cargo.toml
[package]
name = "bar"

[dependencies]
rand = "0.8.5"

Could be written as:

# [PROJECT_DIR]/Cargo.toml
[workspace]
members = ["foo", "bar"]

[workspace.dependencies]
rand = "0.8.5"

# [PROJECT_DIR]/foo/Cargo.toml
[package]
name = "foo"

[dependencies]
rand.workspace = true

# [PROJECT_DIR]/bar/Cargo.toml
[package]
name = "bar"

[dependencies]
rand.workspace = true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the workspace Cargo.toml, foo/Cargo.toml, and bar/Cargo.toml examples in the issue, then review how Clippy lints inspect Cargo workspace metadata. Define the detection, configurability, default category, and inverse-case behavior before implementation. Done means a lint can identify repeated dependencies and provide appropriate workspace-dependency suggestions with tests covering the stated examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.