Lint level cleanups#156564
Merged
Merged
Conversation
It is misnamed, given that it has three fields: `level`, `lint_id`, and `src`. (Presumably the `lint_id` was added later.) This commit renames it as `LevelSpec`. (I also considered `LevelInfo` but that's very generic. `Spec` has pre-existing uses in `LintLevelsProvider::current_specs` and `LintSet::specs` and `ShallowLintLevelMap::specs`.) Related things renamed as well: - `level` -> `level_spec` (where appropriate) - `lint_levels` -> `lint_level_specs` - `get_lint_level` -> `get_lint_level_spec` - `level_and_source` -> `level_spec` - `CodegenLintLevels` -> `CodegenLintLevelSpecs` - `raw_lint_id_level` -> `raw_lint_level_spec` - `lint_level_at_node` -> `lint_level_spec_at_node` - `reveal_actual_level` -> `reveal_actual_level_spec` - `probe_for_lint_level` -> `probe_for_lint_level_spec` This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more `level.level` expressions.
The name is misleading because the field contains a `Level` *and* an `Option<LintExpectationId>`. This commit renames it `level_plus` which better communicates that it's more than just a level.
These methods return `Option<(Self, Option<LintExpectationId>)>`. But all the call sites except one don't look at the `Option<LintExpectationId>`. This commit simplifies these methods to not return the `Option<LintExpectationId>`. This means they no longer need to be passed a closure to compute an `AttrId` (which is usually discarded anyway). The commit also renames `from_attr` as `from_opt_symbol`, because it takes an `Option<Symbol>`, not an `Attribute`. These changes simplify all the call sites that don't need the `Option<LintExpectationId>`, and also the one call site that does (in `LintLevelsBuilder::add`): that call site no longer needs to do an awkward destructuring, and can instead build the appropriate `LintExpectationId` directly.
`LevelSpec` has two related fields, `level` and `lint_id`. This commit makes the fields private (and introduces getters) to ensure they are set together using only valid combinations. The commit also introduces `is_allow` and `is_expect` methods because those are useful.
Collaborator
|
Some changes occurred to the CTFE machinery The Clippy subtree was changed cc @rust-lang/clippy Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in match checking cc @Nadrieril |
| pub level: Level, | ||
| pub lint_id: Option<LintExpectationId>, | ||
| pub struct LevelSpec { | ||
| // This field *must* be private. It must be set in tandem with `lint_id`, only in |
Member
There was a problem hiding this comment.
Nice. 👍
GuillaumeGomez
approved these changes
May 14, 2026
Member
|
Looks all good to me, thanks! @bors r+ rollup |
Contributor
rust-timer
added a commit
that referenced
this pull request
May 14, 2026
Rollup merge of #156564 - nnethercote:LevelSpec, r=GuillaumeGomez Lint level cleanups Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits. r? @GuillaumeGomez
flip1995
pushed a commit
to flip1995/rust
that referenced
this pull request
May 28, 2026
…Gomez Lint level cleanups Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits. r? @GuillaumeGomez
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits.
r? @GuillaumeGomez