How to specify a dev-dependency with the same version as the matching dependency?

Say my Cargo.toml contains this:

some-crate = "1.0.0"

some-crate = {version = "1.0.0", features = ["helpful-debug-feature"]}

I would like to ensure that some-crate is used with the same version in normal builds and tests. But now I have specified the version twice, making it easy to forget changing one of them.

Simply removing the version specification from the dev-dependencies results in a warning that this will become an error in the future.

How can I make the version of some-crate in the dev-dependencies depend on the version of some-crate in the dependencies? The docs don't contain anything about this.

You can use workspace dependencies for that

1 Like


I want to use this for a single-crate repository. Do I need to move my crate into a subfolder for this, or can I somehow have a workspace Cargo.toml and a crate Cargo.toml in the same directory?

You can define a workspace in a single Cargo.toml, but it actually looks like you don't even need to do that. Just adding a [workspace.dependencies] section to a normal crate appears to work without any other changes.

1 Like

Great, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.