-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unexpected cfgs warns on quite-intentional user-cfgs #124821
Comments
cc @Urgau |
To be clear a large part of my complaint here is "there are cases where this is going to produce 100 warnings and then like 10 of them are going to be really good catches but they wind up buried under the other 90". |
The idea is to write a build scripts that emits the check cfg directives to tell rustc which ones to additionally expect. |
That's why we have a mechanism for adding custom cfg, it's the And if you don't want to build scripts, then crates are intended to use Cargo features instead. |
And if someone doesn't want a build script and doesn't want a Cargo feature? |
There isn't a third option, either it's a custom cfg and so users are expected to use a rustc (and by extension Cargo) needs to known the expected cfgs in order to lint on the unexpected ones and since there is two "kind" of cfg, custom cfg and Cargo feature, for Cargo feature there is nothing else to do, and for the custom ones we added the |
There is a third option: be more conservative about when to issue the lint. |
Should this be closed as duplicate of #124800 to consolidate the discussion? |
Yeah for some reason #124800 slipped my notice when I scanned for duplicate issues. |
This allows to find solutions to the false positives that were found in the ecosystem before turning it to `warn` by default again. Most projects hit by this seem to just disable the warning, which indicates that it isn't working as expected. CC rust-lang#124800 CC rust-lang#124804 CC rust-lang#124821 CC hyperium/hyper#3660 CC microsoft/windows-rs#3022 CC rust-bitcoin/rust-bitcoin#2748 CC tokio-rs/tokio#6538
Cargo features are not actually appropriate for all conditional compilation, as not all conditional-compilation-keys are additive. Some are in fact mutually exclusive. Cargo does not have an adequate answer for this problem yet. It is my opinion that in general, except when it is likely a typo (levenshtein 1 from an expected cfg key or key-value pair) or is an unknown value for an expected cfg key, the Rust compiler should not be quite as judgemental of "interesting" uses of cfgs.
Because rustc complained about so many cfgs, this basically clobbered backtrace-rs with a million irrelevant warnings that almost drowned out the one or two interesting things that did need to be fixed.
There are also ecosystem crates that use the pattern of requiring users to set a cfg to enable something, to yield control to the binary's builder, despite being a library crate, or that use it for things that should not be resolved the same way Cargo features are.
The text was updated successfully, but these errors were encountered: