You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When --all-features flag is present, any --features flags are silently ignored.
At first glance that may not seem as a problem, since all features are enabled anyway. But there is a corner case: an [[example]] can depend on a feature of a dependency (required-features = ["dep/something"]). Dependency features are not enabled with --all-features and --features flags are ignored, so it's impossible to build such example with --all-features.
This is especially troublesome when using some external tools (like rust-analyzer) that pass --all-features to cargo.
try running cargo run --example example --all-features --features "tracing/log"
notice that cargo suggests using --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
try running cargo run --example example --all-features --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
notice that it doesn't work either (the suggestion is still the same)
Possible Solution(s)
Do not ignore --features in the presence of --all-features.
This seems to be the right & easy way to resolve this issue. I'll try to come up with a PR later.
Add a warning or an error when --all-features is used with --features.
This does not solve my issue, but at least it improves diagnostics.
Notes
With edition = 2021 (instead of edition = 2018) the behaviour is even weirder:
; sed -i 's/2018/2021/g' ./Cargo.toml
; cargo run --example example --all-features --features="tracing/log"
error: none of the selected packages contains these features: tracing/log
; cargo run --example example --all-features --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
error: none of the selected packages contains these features: aaaaaaaa, bbbbbbbb, cccccccc, dddddddd, eeeeeeee, ffffffff, gggggggg, tracing/log
; cargo run --example example --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/examples/example`
Cargo says that all of the features do not exist, even though they clearly exist.
edition = 2018 though has the oposite problem of allowing clearly non-existing features (by ignoring all of them):
; cargo b --all-features --features "anahsddhjdhjdh definetly_non_existing_feature dep/aaaa"
Compiling tracing v0.1.29
Compiling cargo_all_some_features v0.1.0 (/home/waffle/projects/repos/cargo_all_some_features)
Finished dev [unoptimized + debuginfo] target(s) in 0.94s
Problem
When
--all-features
flag is present, any--features
flags are silently ignored.At first glance that may not seem as a problem, since all features are enabled anyway. But there is a corner case: an
[[example]]
can depend on a feature of a dependency (required-features = ["dep/something"]
). Dependency features are not enabled with--all-features
and--features
flags are ignored, so it's impossible to build such example with--all-features
.This is especially troublesome when using some external tools (like rust-analyzer) that pass
--all-features
to cargo.Steps
cargo run --example example --all-features --features "tracing/log"
--features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
cargo run --example example --all-features --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
Possible Solution(s)
--features
in the presence of--all-features
.This seems to be the right & easy way to resolve this issue. I'll try to come up with a PR later.
--all-features
is used with--features
.This does not solve my issue, but at least it improves diagnostics.
Notes
With
edition = 2021
(instead ofedition = 2018
) the behaviour is even weirder:Cargo says that all of the features do not exist, even though they clearly exist.
edition = 2018
though has the oposite problem of allowing clearly non-existing features (by ignoring all of them):See also: #10332
Version
The text was updated successfully, but these errors were encountered: