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.

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