Skip to content

Copy only inherited workspace dependencies into generated manifest - #344

Merged
dtolnay merged 1 commit into
dtolnay:masterfrom
tamaro-skaljic:fix/issue-343-unused-workspace-dependency-warnings
Oct 7, 2026
Merged

dtolnay merged 1 commit into
dtolnay:masterfrom
tamaro-skaljic:fix/issue-343-unused-workspace-dependency-warnings

Conversation

@tamaro-skaljic

@tamaro-skaljic tamaro-skaljic commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Note: This pull request's description and code changes were generated using AI, but reviewed by me.

This PR contains only the fix, but an end-to-end test exists on a separate branch, see below.
If the test should be added to the repository, let me know and I will add the commits here too.

The Issue

Fixes #343.

Cargo's new warn-by-default lint cargo::unused_workspace_dependencies, in beta 1.100 and nightly, warns about every [workspace.dependencies] entry that no workspace member inherits.

trybuild copies the whole table into the generated manifest, but the generated package inherits only the entries that the crate under test uses. So every Cargo invocation by trybuild warns once for each of the other entries. The warnings appear while the dependencies build, and again in the STDERR block of every pass test.

The Solution

With this PR trybuild copies only the entries that the generated package inherits with workspace = true, from its [dependencies], which include the dev-dependencies, or from any [target.*.dependencies].

Dropping the other entries can't change resolution, because Cargo only uses a workspace dependency through a member that inherits it.

Considered Alternatives

Allowing the lint instead doesn't work:

  • [lints.cargo] in the generated package doesn't affect this workspace-level lint.

  • [workspace.lints.cargo] silences it, but Cargo without stable cargo lints, such as 1.98.1 and 1.93.0, then warns unused manifest key `lints.cargo` on every invocation.

Verification / Testing

See tests/test_workspace.rs, on branch test/issue-343-unused-workspace-dependency-warnings.

The test writes a fixture workspace into CARGO_TARGET_TMPDIR. There, the crate under test inherits workspace dependencies through [dependencies], [dev-dependencies] (with trybuild itself), [build-dependencies], [target.'cfg(unix)'.dependencies] and [target.'cfg(windows)'.dev-dependencies]. A second member inherits the crate under test and an entry of its own.

The test runs cargo test there, over a pass + compile_fail suite and a compile_fail-only suite, and asserts three things:

  • the run succeeds;

  • nothing prints unused workspace dependency;

  • the generated [workspace.dependencies] holds exactly the four inherited entries.

Building the fixture compiles trybuild a second time, which took about 16 seconds on a cold cache here and 7 seconds warm.

On Windows, it also needs a checkout path shorter than about 118 characters, because link.exe can't write the deeper paths of the fixture's binaries.

Results on Windows 11, with RUSTFLAGS=-Dwarnings:

Toolchain Before the fix After the fix
nightly: cargo 1.100.0-nightly (7941be6fb 2026-09-11) fails: 9 warnings, for build-dep, member and other-dep passes
beta: cargo 1.100.0-beta.4 (7552a885e 2026-09-29) fails: the same 9 warnings passes
cargo 1.98.1 (797e8a9bc 2026-08-05) fails: no lint yet, but the generated manifest also holds build-dep, member and other-dep passes
cargo 1.93.0 not run passes

With the fix, trybuild's own cargo test passes on nightly with CI's RUSTFLAGS="-Dwarnings -Zrandomize-layout", and on 1.98.1 and 1.93.0. cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic is clean, and so is rustfmt.

Before the fix: the STDERR block of the fixture's pass test on nightly
warning: unused workspace dependency `build-dep`
  --> Cargo.toml:35:25
   |
35 | [workspace.dependencies.build-dep]
   |                         ^^^^^^^^^
   |
   = note: `cargo::unused_workspace_dependencies` is set to `warn` by default
help: consider removing the workspace dependency `build-dep`
warning: unused workspace dependency `member`
  --> Cargo.toml:44:25
   |
44 | [workspace.dependencies.member]
   |                         ^^^^^^
   |
help: consider removing the workspace dependency `member`
warning: unused workspace dependency `other-dep`
  --> Cargo.toml:47:25
   |
47 | [workspace.dependencies.other-dep]
   |                         ^^^^^^^^^
   |
help: consider removing the workspace dependency `other-dep`

pr-343-test-results.md

🤖 Generated with Claude Code

Cargo 1.100 warns about every [workspace.dependencies] entry that no
workspace member inherits (cargo::unused_workspace_dependencies). The
generated manifest copied the whole table, but the generated package
inherits only the entries that the crate under test uses, so every Cargo
invocation by trybuild warned about all the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@dtolnay
dtolnay merged commit ce13e9b into dtolnay:master Oct 7, 2026
12 checks passed
@tamaro-skaljic
tamaro-skaljic deleted the fix/issue-343-unused-workspace-dependency-warnings branch October 8, 2026 03:51
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.

Generated manifest triggers cargo::unused_workspace_dependencies for every workspace dependency that the tested crate doesn't use

2 participants