-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
compiler/middle/lint: Suggest #[expect(dead_code)] instead of #[allow(dead_code)]
#147717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
rustbot has assigned @petrochenkov. Use |
|
r? @estebank since we already talked about it :) |
| "`{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" }; |
There was a problem hiding this comment.
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.
|
This is great! I wonder if it would be hard to make this conditional on the |
I don't think rustc has access to that information from cargo. |
47d1a5a to
d2f2501
Compare
This comment has been minimized.
This comment has been minimized.
|
I noticed one small complication: If the code is used in tests, but not from public API of a library, then the I wonder whether we should suggest both |
d2f2501 to
11f947c
Compare
|
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. |
|
@estebank any thoughts on this? if you don't have time, should I find a different reviewer? |
Until now the compiler suggested
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 😆