Skip to content

Split LintExpectationIds#156596

Open
nnethercote wants to merge 5 commits into
rust-lang:mainfrom
nnethercote:split-LintExpectation
Open

Split LintExpectationIds#156596
nnethercote wants to merge 5 commits into
rust-lang:mainfrom
nnethercote:split-LintExpectation

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

This PR makes clearer where stable and unstable LintExpectationIds can occur, plus a few other small cleanups. Details in individual commits.

r? @GuillaumeGomez

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

The Clippy subtree was changed

cc @rust-lang/clippy

@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. labels May 15, 2026
Comment thread compiler/rustc_lint/src/levels.rs Outdated
// -A,-W,-D flags, a `Symbol` for the flag itself and `LevelSpec` for which
// flag.
specs: FxIndexMap<LintId, LevelSpec>,
// -A,-W,-D flags, a `Symbol` for the flag itself and `LevelSpec` for which flag.
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez May 16, 2026

Choose a reason for hiding this comment

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

Is there still a Symbol in here?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No. LintId wraps Lint which contains a &'static str for the lint name. And the -A,-W,-D part I think is also inaccurate, it's about the lint level which could be specified on the command line but also via an attribute like #[allow(...)].

I think the comment is very out of date and it wasn't that informative anyway. The type itself is fairly straightforward and any alternative comment I could come up with was just something obvious like "a map of lints to lint levels". So I have just removed it.

`LintExpectationId` has two variants, `Unstable` and `Stable`. There are
some places where both variants are possible, but there are also places
where only one of `Unstable` or `Stable` is possible.

This commit encodes this into the type system by introducing
new types `UnstableLintExpectationId` and `StableLintExpectationId`. The
variants of `LintExpectationId` now enclose these. This makes it clearer
what values are possible where.

Other things of note:
- `LintLevelsProvider` gets an associated type and some method changes.
- `LintContext` gets an associated type.
- `LevelSpec` is made generic. `UnstableLevelSpec` and `StableLevelSpec`
  typedefs are added.
- The unstable types are now guaranteed by the type system to never be
  stably hashed. Previously this was a runtime check.
I find these make the code harder to understand.
Describing things that took me a while to work out.
@nnethercote nnethercote force-pushed the split-LintExpectation branch from d8bcae9 to 6c9d519 Compare May 16, 2026 11:20
@GuillaumeGomez
Copy link
Copy Markdown
Member

Thanks!

r=me once CI pass.

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-clippy Relevant to the Clippy team. 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.

3 participants