Skip to content

allow unused_features lint#114

Merged
BennoLossin merged 1 commit intomainfrom
dev/allow-unused-features
Mar 7, 2026
Merged

allow unused_features lint#114
BennoLossin merged 1 commit intomainfrom
dev/allow-unused-features

Conversation

@BennoLossin
Copy link
Member

The unused_features lint was introduced in rust-lang/rust#152164, presumably landing in Rust 1.96.0. We simplified the way we use features in #102, always enabling them when building the crate with certain features enabled. For this reason allow the lint.

I plan to also add a new CI run that enables the lint & checks if we can remove certain features. Will do so at a later point in time.

This PR fixes the CI failure observed in https://github.com/Rust-for-Linux/pin-init/actions/runs/22754182535

The `unused_features` lint was introduced in [1], presumably landing in
Rust 1.96.0. We simplified the way we use features in #102, always
enabling them when building the crate with certain features enabled. For
this reason allow the lint.

Link: rust-lang/rust#152164 [1]
Signed-off-by: Benno Lossin <lossin@kernel.org>
Copy link
Member

@nbdd0121 nbdd0121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also need to enable this in general for other kernel crates, I think?

@BennoLossin
Copy link
Member Author

Yes, I already notified Miguel (although in the kernel it only is a warning as opposed to here where it is an error due to our deny(warnings)).

@nbdd0121
Copy link
Member

nbdd0121 commented Mar 6, 2026

There's CONFIG_WERROR so it's also problematic

@ojeda
Copy link
Member

ojeda commented Mar 6, 2026

Yeah, e.g. from one of my builds:

error: feature `lint_reasons` is declared but not used
   --> rust/pin-init/src/lib.rs:267:56
    |
267 | #![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
    |                                                        ^^^^^^^^^^^^
    |
    = note: `-D unused-features` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_features)]`

I will put a workaround for rust.docs.kernel.org for now.

@BennoLossin BennoLossin marked this pull request as ready for review March 7, 2026 06:39
@BennoLossin BennoLossin merged commit bad9e6a into main Mar 7, 2026
26 checks passed
@BennoLossin
Copy link
Member Author

I tried to set up a CI check, but it didn't work, since the unused_features lint apparently also lints when a feature is stable and used, see rust-lang/rust#153523

@BennoLossin BennoLossin deleted the dev/allow-unused-features branch March 8, 2026 20:58
@ojeda
Copy link
Member

ojeda commented Mar 12, 2026

For Linux, I am also hitting:

warning: feature `used_with_arg` is declared but not used
 --> <crate attribute>:1:93
  |
1 | #![feature(asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg)]
  |                                                                                             ^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default

I think it is simpler for us to simply allow it globally because one way or the other we will hit it.

@BennoLossin
Copy link
Member Author

Did you try it with a nightly that includes the fix for rust-lang/rust#153523? It might go away with that (at least for some builds, we probably still end up with cfg's disabling all uses of a certain feature, so we should still allow the lint).

@ojeda
Copy link
Member

ojeda commented Mar 12, 2026

used_with_arg is unstable, so the fix wouldn't help, no?

But, yeah, I tested with the latest nightly, which already includes the fix.

And, yeah, conditional compilation (and generally compiling crates that may not use a particular feature) will likely be an issue.

@ojeda
Copy link
Member

ojeda commented Mar 12, 2026

I mean, we could require crates to enable features manually (even if we still only allow those to be enabled via -Zallow-features, i.e. we avoid -Zcrate-attr), but I don't think it is worth it making all developers worry about it just for a lint.

@ojeda
Copy link
Member

ojeda commented Mar 12, 2026

ojeda added a commit to Rust-for-Linux/linux that referenced this pull request Mar 12, 2026
Starting with the upcoming Rust 1.96.0 (to be released 2026-05-28),
`rustc` introduces the new lint `unused_features` [1], which warns [2]:

    warning: feature `used_with_arg` is declared but not used
     --> <crate attribute>:1:93
      |
    1 | #![feature(asm_const,asm_goto,arbitrary_self_types,lint_reasons,offset_of_nested,raw_ref_op,used_with_arg)]
      |                                                                                             ^^^^^^^^^^^^^
      |
      = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default

The original goal of using `-Zcrate-attr` automatically was that there
is a consistent set of features enabled and managed globally for all
Rust kernel code (modulo exceptions like the `rust/` crated).

While we could require crates to enable features manually (even if we
still keep the `-Zallow-features=` list, i.e. removing the `-Zcrate-attr`
list), it is not really worth making all developers worry about it just
for a new lint.

The features are expected to eventually become stable anyway (most already
did), and thus having to remove features in every file that may use them
is not worth it either.

Thus just allow the new lint globally.

The lint actually existed for a long time, which is why `rustc` does
not complain about an unknown lint in the stable versions we support,
but it was "disabled" years ago [3], and now it was made to work again.

For extra context, the new implementation of the lint has already been
improved to avoid linting about features that became stable thanks to
Benno's report and the ensuing discussion [4] [5], but while that helps,
it is still the case that we may have features enabled that are not used
for one reason or another in a particular crate.

Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Link: rust-lang/rust#152164 [1]
Link: Rust-for-Linux/pin-init#114 [2]
Link: rust-lang/rust#44232 [3]
Link: rust-lang/rust#153523 [4]
Link: rust-lang/rust#153610 [5]
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260312111014.74198-1-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants