Skip to content

Bug: workspace-duplicate triggers on renamed dependencies #707

Open
@Nemo157

Description

Describe the bug

When using a renamed dependency in one crate of a workspace (e.g. as is useful for testing macro hygienity) the workspace-duplicate lint triggers with no way to suppress it.

To reproduce

> cat >>Cargo.toml <<-END
[workspace]
resolver = "2"
END

> cargo new foo --lib && cargo new bar && cargo new baz
    Creating library `foo` package
      Adding `foo` as member of workspace at `/tmp/scratch.rust.2024-10-11T15-00.ay4VzE`
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    Creating binary (application) `bar` package
      Adding `bar` as member of workspace at `/tmp/scratch.rust.2024-10-11T15-00.ay4VzE`
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
    Creating binary (application) `baz` package
      Adding `baz` as member of workspace at `/tmp/scratch.rust.2024-10-11T15-00.ay4VzE`
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

> cat >>bar/Cargo.toml <<-END
my-foo = { package = "foo", path = "../foo" }
END

> cat >>baz/Cargo.toml <<-END
foo.workspace = true
END

> cat >>Cargo.toml <<-END
[workspace.dependencies]
foo.path = "foo"
END

> cat >>deny.toml <<-END
[bans.workspace-dependencies]
duplicates = "warn"
include-path-dependencies = true
END

> cargo deny check bans
warning[workspace-duplicate]: crate foo = 0.1.0 is used 2 times in the workspace, but not all declarations use the shared workspace dependency
  ┌─ /tmp/scratch.rust.2024-10-11T15-00.ay4VzE/Cargo.toml:4:1

4 │ foo.path = "foo"
  │ ─── workspace dependency

  ┌─ /tmp/scratch.rust.2024-10-11T15-00.ay4VzE/bar/Cargo.toml:7:1

7 │ my-foo = { package = "foo", path = "../foo" }
  │ ━━━━━━                ─── note the dependency is renamed

  ├ foo v0.1.0
    ├── bar v0.1.0
    └── baz v0.1.0

bans ok

cargo-deny version

cargo-deny 0.16.1

What OS were you running cargo-deny on?

Linux

Additional context

If I could use the workspace dependency with renaming I would, but this is not something cargo supports.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions