cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Using `dep:` syntax in Cargo.toml makes it impossible to enable features for dependencies unless you also have a feature by that name

Open LoganDark opened this issue 2 years ago • 3 comments

Any crate with this Cargo.toml, or any one like it:

[package]
name = 'whatever'
version = '0.1.0'
edition = '2021'

[features]
default = ['font', 'allsorts/flate2_rust']
font = ['dep:allsorts']

[dependencies]
allsorts = { version = '~0.10.0', optional = true, default-features = false }

fails to compile because of the allsorts/flate2_rust, even though it shouldn't (allsorts is a dependency, not a feature name).

Adding an allsorts feature, even a completely empty one, fixes the error:

[package]
name = 'whatever'
version = '0.1.0'
edition = '2021'

[features]
default = ['font', 'allsorts/flate2_rust']
font = ['dep:allsorts']
allsorts = []

[dependencies]
allsorts = { version = '~0.10.0', optional = true, default-features = false }

so this is probably a misbehaving lint. I don't want an extra allsorts feature (in my real crate, font is more than just allsorts, and enabling allsorts on its own makes 0 sense).

If this lint exists for encapsulation purposes, I would like to be able to do dep:allsorts/flate2_rust at least, if there is no outer-facing allsorts feature (although I'd add one in that case so that downstream crates can configure which flate2 backend they want).

Active toolchain:

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.63.0-nightly (dc80ca78b 2022-06-21)

I have made a minimum effort to search for duplicate issues, but "dep cargo feature" is such a generic search term that it gives thousands of results.

LoganDark avatar Jun 24 '22 06:06 LoganDark

Thanks for the report! I'm not sure how we missed that.

ehuss avatar Jun 24 '22 19:06 ehuss

Interesting, I was confused because I thought I was using this setup in a crate of mine just fine; but it looks like if you use allsorts?/flate2_rust it works fine, and I happened to be using weak-features for all my namespaced crates.

Nemo157 avatar Jul 28 '22 14:07 Nemo157

it looks like if you use allsorts?/flate2_rust it works fine

Thanks for the workaround :)

LoganDark avatar Jul 28 '22 14:07 LoganDark

As this doesn't seem to be very active, I'll try it and see what happens :) @rustbot claim

blyxyas avatar Apr 18 '23 19:04 blyxyas