-
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
Unknown feature flags should trigger a warning or error #52053
Comments
I think this is slightly more important as we are encouraging people to try out the 2018 edition via a feature flag, but I'd find it useful to have back in any case. |
This is #44232, though there it only talks about unused features, rather than invalid, features. However, that's the issue that the code points to for this: |
I this is not, I believe, a duplicate of #44232 — this is not about features that are not used but rather about features that are totally invalid. |
Marking as P-high just because it's bad. I'm going to try and write up some mentoring instructions. "How hard can it be" |
To clarify: in the past, the unused or invalid feature lint was the same lint — which is why #44232 only seems to mention unused features (hence the The difficult part here is detecting invalid lib features, because we don't have a complete list of all the lib features (lang features are easy to check, on the other hand). We could do the validation here if we could check against a set of all known library features: However, previously it was conflated into this check: From what I understand at the moment, this isn't going to be straightforward. Nowhere are all the library features gathered. Instead, we collect all the potential library features that have been declared, and then for each use of an item, we check whether it requires a library feature and then whether that library feature was declared. To actually detect invalid features (i.e. to distinguish them from unused features), I think we are going to need to build up a set of valid library features. I'm not sure how awkward this would be yet. This would probably be functionally achievable by calling |
visited for triage. @varkor are you waiting for more guidance on potential ways to proceed? I cannot tell from your comment whether you are implicitly asking for this bug to be downgraded in priority, due to potentially-inherent inefficiencies in ways to resolve it? |
That first comment was just clarifying what the problem was, and why it's slightly more difficult than we thought it might be. I still need to give it some more thought as the best way to proceed; hopefully I'll have something by next week. |
I have a fix for this, which essentially involves giving lib features the same treatment as language features. However, it adds a massive list of features (~800 lines' worth) to I'm not sure of a way to detect whether a lib feature is valid without either storing them in a list, or checking every single method, etc. in core, alloc, std, etc. (which seems to be why the previous lint was "feature unused or unknown"). My question is whether we want to take this approach, or whether this is overkill, and there's a better way? |
I believe we do successfully lint on all library features when they're unused, so perhaps somehow that logic can be reused to avoid introducing a list anywhere? That is, we'd wait until we have that information and now emit the unused/unknown warning on any features that we don't recognize as a lang feature. Ideally of course we'd so of independent of lang-ness but since we don't properly track lang features yet we can just skip over them in the warning. Does that make sense? |
Just summarising a few points from an IRC discussion here:
|
visited for triage; PR #52644 looks like some great work to address this, and it seems like the discussion has essentially migrated there. |
Add errors for unknown, stable and duplicate feature attributes - Adds an error for unknown (lang and lib) features. - Extends the lint for unnecessary feature attributes for stable features to libs features (this already exists for lang features). - Adds an error for duplicate (lang and lib) features. ```rust #![feature(fake_feature)] //~ ERROR unknown feature `fake_feature` #![feature(i128_type)] //~ WARNING the feature `i128_type` has been stable since 1.26.0 #![feature(non_exhaustive)] #![feature(non_exhaustive)] //~ ERROR duplicate `non_exhaustive` feature attribute ``` Fixes #52053, fixes #53032 and address some of the problems noted in #44232 (though not unused features). There are a few outstanding problems, that I haven't narrowed down yet: - [x] Stability attributes on macros do not seem to be taken into account. - [x] Stability attributes behind `cfg` attributes are not taken into account. - [x] There are failing incremental tests.
Thanks, @varkor ! I know that was a slog to get merged! |
This code compiles with no warnings or errors on 1.28.0-nightly (2018-06-28 e3bf634). As of 2017-08-11, it prints a warning ("unused or unknown feature").
@Mark-Simulacrum ran a bisection and found:
/cc @alexcrichton
The text was updated successfully, but these errors were encountered: