Skip to content

Conversation

@Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Oct 15, 2025

Until now the compiler suggested

help: to override -W unused add #[allow(dead_code)]

when encountering e.g. an unused function in the codebase.

This PR changes the suggestion to #[expect(dead_code)], which will warn again once the code is being used somewhere. This is helpful because it lets the developer know that the attribute can now be removed again. Without this the codebase will eventually be littered with stray #[allow(dead_code)] attributes that are no longer serving any purpose.

This was suggested in https://bsky.app/profile/steveklabnik.com/post/3m2uh7pf6e225 and I agreed strongly enough to take a look and implement it 😆

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 15, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Turbo87
Copy link
Member Author

Turbo87 commented Oct 15, 2025

r? @estebank

since we already talked about it :)

@rustbot rustbot assigned estebank and unassigned petrochenkov Oct 15, 2025
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
if matches!(orig_level, Level::Warn | Level::Deny) {
let suggestion = if name == "dead_code" { "expect" } else { "allow" };
Copy link
Member Author

Choose a reason for hiding this comment

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

I scoped this to only the dead_code suggestion for now. It might make sense to extend it to others in the future too though.

@djc
Copy link
Contributor

djc commented Oct 15, 2025

This is great! I wonder if it would be hard to make this conditional on the rust-version of the crate in question?

@estebank
Copy link
Contributor

I wonder if it would be hard to make this conditional on the rust-version of the crate in question?

I don't think rustc has access to that information from cargo.

@rustbot

This comment has been minimized.

@Turbo87
Copy link
Member Author

Turbo87 commented Oct 25, 2025

I noticed one small complication:

error: this lint expectation is unfulfilled
   --> src/coords.rs:100:14
    |
100 |     #[expect(dead_code)]
    |              ^^^^^^^^^
    |
    = note: `-D unfulfilled-lint-expectations` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]`

error: could not compile `openair` (lib test) due to 1 previous error

If the code is used in tests, but not from public API of a library, then the expect() will trigger a lint expectation is unfulfilled warning for the lib test compile target. with allow() this would not be an issue because it allows both used and unused cases.

I wonder whether we should suggest both expect() and allow() for dead_code instead?

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Turbo87
Copy link
Member Author

Turbo87 commented Dec 2, 2025

@estebank any thoughts on this? if you don't have time, should I find a different reviewer?

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants