Skip to content

WIP: Lint unused features#152164

Draft
mu001999 wants to merge 3 commits intorust-lang:mainfrom
mu001999-contrib:lint/unused_features
Draft

WIP: Lint unused features#152164
mu001999 wants to merge 3 commits intorust-lang:mainfrom
mu001999-contrib:lint/unused_features

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Feb 5, 2026

Fixes #44232
Fixes #151752

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

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

this is neat! in the future, it would be easier to review if you split the rename into a separate commit from the change in behavior.

could you add some tests for this please?

View changes since this review

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from cb9b84c to cd83e12 Compare February 5, 2026 15:31
@mu001999
Copy link
Contributor Author

mu001999 commented Feb 5, 2026

Initial implementation completed. I plan to add more tests and check whether features in rustc are reported as unused correctly or not.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from cd83e12 to 2945856 Compare February 6, 2026 00:38
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2945856 to 36c0a20 Compare February 6, 2026 01:00
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |
206 | #![feature(riscv_target_feature)]
    |            ^^^^^^^^^^^^^^^^^^^^

warning: feature `rtm_target_feature` is declared but not used
   --> library/core/src/lib.rs:207:12
    |
207 | #![feature(rtm_target_feature)]
    |            ^^^^^^^^^^^^^^^^^^

warning: feature `s390x_target_feature` is declared but not used
   --> library/core/src/lib.rs:208:12
    |
---
   Compiling unwind v0.0.0 (/checkout/library/unwind)
warning: feature `libc` is declared but not used
 --> library/unwind/src/lib.rs:7:47
  |
7 | #![cfg_attr(not(target_env = "msvc"), feature(libc))]
  |                                               ^^^^
  |
  = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default

[RUSTC-TIMING] unwind test:false 0.078
---

warning: feature `string_replace_in_place` is declared but not used
  --> library/alloc/src/lib.rs:88:50
   |
88 | #![cfg_attr(not(no_global_oom_handling), feature(string_replace_in_place))]
   |                                                  ^^^^^^^^^^^^^^^^^^^^^^^

warning: feature `assert_matches` is declared but not used
  --> library/alloc/src/lib.rs:92:12
   |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc could warn if a feature is unused Re-enable detection of unused library #![feature] directives

4 participants