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

--features is silently ignored when --all-features is present #10333

Closed
WaffleLapkin opened this issue Jan 26, 2022 · 0 comments · Fixed by #10337
Closed

--features is silently ignored when --all-features is present #10333

WaffleLapkin opened this issue Jan 26, 2022 · 0 comments · Fixed by #10337
Labels
C-bug Category: bug

Comments

@WaffleLapkin
Copy link
Member

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

  1. Clone the example repository: https://github.com/WaffleLapkin/cargo_all_some_features
  2. try running cargo run --example example --all-features --features "tracing/log"
  3. notice that cargo suggests using --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
  4. try running cargo run --example example --all-features --features="aaaaaaaa bbbbbbbb cccccccc dddddddd eeeeeeee ffffffff gggggggg tracing/log"
  5. notice that it doesn't work either (the suggestion is still the same)

Possible Solution(s)

  1. 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.
  2. 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

See also: #10332

Version

cargo 1.60.0-nightly (95bb3c92b 2022-01-18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant