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

Unknown feature flags should trigger a warning or error #52053

Closed
shepmaster opened this issue Jul 4, 2018 · 12 comments · Fixed by #52644
Closed

Unknown feature flags should trigger a warning or error #52053

shepmaster opened this issue Jul 4, 2018 · 12 comments · Fixed by #52644
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shepmaster
Copy link
Member

#![feature(wuzzy)]
fn main() {}

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:

bisection claims 2017-09-09 is the first nightly that regressed, but I'm still trying to narrow down a specific commit

I suspect #44142 (the commit range if I'm reading it right is d93036a to dead08c).

/cc @alexcrichton

@shepmaster
Copy link
Member Author

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.

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 4, 2018
@kennytm kennytm added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jul 4, 2018
@varkor
Copy link
Member

varkor commented Jul 4, 2018

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:
https://github.com/rust-lang/rust/blob/08ccf2e59da8e49772ff74b0dab3140d45d7c7dc/src/librustc/middle/stability.rs#L827-L841

@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis nikomatsakis self-assigned this Jul 5, 2018
@nikomatsakis nikomatsakis added the P-high High priority label Jul 5, 2018
@nikomatsakis
Copy link
Contributor

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"

@nikomatsakis nikomatsakis added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 5, 2018
@varkor varkor assigned varkor and unassigned nikomatsakis Jul 5, 2018
@varkor
Copy link
Member

varkor commented Jul 6, 2018

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 unused or unknown feature message).

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:
https://github.com/rust-lang/rust/blob/08ccf2e59da8e49772ff74b0dab3140d45d7c7dc/src/libsyntax/feature_gate.rs#L1948

However, previously it was conflated into this check:
https://github.com/rust-lang/rust/blob/08ccf2e59da8e49772ff74b0dab3140d45d7c7dc/src/librustc/middle/stability.rs#L827-L841

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 find_stability for every set of item attributes:
https://github.com/rust-lang/rust/blob/08ccf2e59da8e49772ff74b0dab3140d45d7c7dc/src/libsyntax/attr.rs#L973-L977
And storing the feature names in a table. It seems likely this is not efficient and also might not mesh well with incremental. I think this has essentially the same technical difficulties as #44232, even if it's not merged again unused feature detection.

@pnkfelix
Copy link
Member

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?

@varkor
Copy link
Member

varkor commented Jul 12, 2018

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.

@varkor
Copy link
Member

varkor commented Jul 21, 2018

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 feature_gate.rs and has the additional disadvantage that changing stability of a lib feature requires recompiling rustc.

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?

@Mark-Simulacrum
Copy link
Member

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?

@varkor
Copy link
Member

varkor commented Jul 22, 2018

Just summarising a few points from an IRC discussion here:

@pnkfelix
Copy link
Member

visited for triage; PR #52644 looks like some great work to address this, and it seems like the discussion has essentially migrated there.

bors added a commit that referenced this issue Aug 6, 2018
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.
@shepmaster
Copy link
Member Author

Thanks, @varkor ! I know that was a slog to get merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants