close
Skip to content

Lint level cleanups#156564

Merged
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
nnethercote:LevelSpec
May 14, 2026
Merged

Lint level cleanups#156564
rust-bors[bot] merged 5 commits into
rust-lang:mainfrom
nnethercote:LevelSpec

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits.

r? @GuillaumeGomez

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.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 14, 2026

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 14, 2026
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
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez May 14, 2026

Choose a reason for hiding this comment

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

@GuillaumeGomez
Copy link
Copy Markdown
Member

Looks all good to me, thanks!

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 14, 2026

📌 Commit bc127a6 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2026
rust-bors Bot pushed a commit that referenced this pull request May 14, 2026
Rollup of 3 pull requests

Successful merges:

 - #146220 (feat(rustdoc): stabilize `--emit` flag)
 - #153785 (Hand-written Debug implementation for `TypeTest`)
 - #156564 (Lint level cleanups)
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
@rust-bors rust-bors Bot merged commit 1f5737c into rust-lang:main May 14, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 14, 2026
@nnethercote nnethercote deleted the LevelSpec branch May 15, 2026 05:16
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants