Re-enable detection of unused library #![feature] directives
Currently the compiler will warn users about unused #![feature] directives if they're (a) a library feature and (b) not actually ever used. The compiler doesn't currently warn you about unused #![feature] directives tied to language features.
In the process of making the stability annotations more incremental-friendly (https://github.com/rust-lang/rust/issues/44137) this check in the compiler has proven to be very difficult to make incremental. Namely what's happening here is:
- There's a function,
check_stability, which is used to verify that an API can actually be used. - In this function if the API in question is unstable and the feature is activated, then this feature name is stored off in a side table.
- As we run through the compiler this side table gets bigger and bigger. Right now this table is mostly built up during typeck. (I don't know the precise reason as to why it's in typeck, personally)
- Finally near the end of compilation we go through this table and use it to warn about unused
#![feature]directives.
This "put things in a table on the side" behavior isn't very incremental friently and isn't too easy to transition over to the query system. For now this specific warning seems like it probably isn't that important at Rust 1.20.0 (while it was probably very important at Rust 1.0.0). I'm going to comment this out for now so we're not going to get lints/warnings about unused library features.
This is a FIXME to track re-enabling this warning!
Note that this also applies to the lint of "this
#[feature]isn't needed because it's stable", that gets emitted at most once but it's not clear how to do that any more.Alex Crichton at 2017-09-01 00:34:51
Oh, so the "unused feature" lint is going to be disabled entirely? That could potentially unblock me over at https://github.com/rust-lang/rust/pull/43017#issuecomment-326433381 as I currently can't figure out how to correctly populate the side table you're talking about.
Alex Burka at 2017-09-01 05:27:03
Maybe side tables are fundamentally incompatible with incremental and the set of used features (perhaps optimized as a bit map) should be part of the “result” of relevant compiler queries?
Simon Sapin at 2017-12-16 06:02:23
How is this different from an unused item, say
struct Foo;that's never used inside the crate? This unused lint works well with incremental compilation. The tasks seem similar to me.est31 at 2019-08-28 11:36:06
Nominating at the request of @est31 in https://github.com/rust-lang/rust/issues/63850.
Mazdak Farrokhzad at 2019-08-29 02:40:01
Visiting as part of compiler triage.
I agree this would be nice, but it is certainly not P-high. It seems connected to the end-to-end query discussion. Based on Alex's comment, seems like there is some design work. In an effort to get somebody to maybe leave some thoughts, I'll cc @rust-lang/compiler, but not sure what else to do here. =)
Niko Matsakis at 2019-08-29 15:56:38
Hi, sorry to bother you with the old issue. I'm looking for a command or a tool to detect the unnecessary features and I found this issue. Would you please tell that if the issue is still in the plan? Thanks a lot.
Croxx at 2024-03-08 15:20:17