Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev-dependencies] referencing [dependencies] causes warnings #7024

Open
ghost opened this issue Jun 8, 2019 · 4 comments
Open

[dev-dependencies] referencing [dependencies] causes warnings #7024

ghost opened this issue Jun 8, 2019 · 4 comments
Labels
A-dev-dependencies Area: [dev-dependencies] C-bug Category: bug S-needs-rfc Status: Needs an RFC to make progress.

Comments

@ghost
Copy link

ghost commented Jun 8, 2019

Hello Rust developers,

My Problem

In Cargo.toml, in order to use same version of a dependency for both [dependencies] and [dev-dependencies], I use a reference:

[dependencies]
some = '0.1'

[dev-dependencies]
some = { package='some' }

It compiles, but with a warning: dependency (some) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions.

Possible Solution(s)

Both section can declare their own version strings, and the warning will be gone. However, I'm using references to reduces mistakes, maintenance cost... Yes it is just a small version string, but I wish to be able to declare it in one single place.

Beside, references are legal: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html -- May I ask if you could make my problem above a legal declaration?

Notes

Output of cargo version: cargo 1.35.0 (6f3e9c367 2019-04-04)

Thank you,

@ghost ghost added the C-bug Category: bug label Jun 8, 2019
@sfackler
Copy link
Member

sfackler commented Jun 8, 2019

Your real use case may be something more complex, but in the case of some, you can delete the dev-dependency entirely, and things will still work.

@ghost
Copy link
Author

ghost commented Jun 8, 2019

@sfackler Thanks I understand. In my project, some belongs to an optional feature. That's why I need [dev-dependencies] section.

@ehuss ehuss added the A-dev-dependencies Area: [dev-dependencies] label Jun 24, 2019
@SoniEx2
Copy link

SoniEx2 commented Jan 12, 2023

hmm interesting

ran into this warning when trying to use tokio

there's no point to enable tokio test-util in prod so it made sense to just put tokio = {features=["test-util"]} in dev-dependencies and let it add onto prod features but that brings up this warning.

[dependencies]
tokio = {version = "1.23.0", features = ["..."]}
[dev-dependencies]
tokio = {features = ["test-util"]}

@epage
Copy link
Contributor

epage commented Nov 1, 2023

With workspace inheritance you can do

[workspace.dependencies]
tokio = "1.23.0"

[dependencies]
tokio = {workspace = true, features = ["..."]}
[dev-dependencies]
tokio = {workspace = true, features = ["test-util"]}

On a somewhat related note, rust-lang/rfcs#3516 proposes a syntax for getting a version from one of your dependencies.

$ cargo add tokio
$ # Many moons later
$ cargo add tokio --dev -F test-util

cargo add will fill in the dev-dependencies version requirement based on the dependencies entry.

I wonder how often people run into this problem for us to consider the upfront work and continued maintenance to support this.

Note: it looks like tokio = {features = ["test-util"]} is treated as tokio = {version = "*", features = ["test-util"]} and can be used besides these scenarios. Changing behavior here would technically be a breaking change. We'd likely want to make this a hard error before even considering adding it back in for some cases.

@epage epage added the S-needs-rfc Status: Needs an RFC to make progress. label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dev-dependencies Area: [dev-dependencies] C-bug Category: bug S-needs-rfc Status: Needs an RFC to make progress.
Projects
None yet
Development

No branches or pull requests

4 participants