Skip to content

Set up API to make it possible to pass closures instead of AttributeLint#154432

Open
GuillaumeGomez wants to merge 2 commits intorust-lang:mainfrom
GuillaumeGomez:try-rm-AttributeLint
Open

Set up API to make it possible to pass closures instead of AttributeLint#154432
GuillaumeGomez wants to merge 2 commits intorust-lang:mainfrom
GuillaumeGomez:try-rm-AttributeLint

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez commented Mar 26, 2026

View all comments

Part of #153099.

This PR sets up the base implementations needed to remove AttributeLintKind entirely and migrate two variants as examples.

r? @JonathanBrouwer

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Mar 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 26, 2026

JonathanBrouwer is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Added the missing file and fixed the typo. Time to run a perf check.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 26, 2026
Set up API to make it possible to pass closures instead of `AttributeLint`
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 26, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 27, 2026

☀️ Try build successful (CI)
Build commit: 8dcd0b9 (8dcd0b95692c85cfd497ecfb5770e55e4796ba80, parent: 23903d01c237d7c7d4fb62b82ca846bc45de4e0c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (8dcd0b9): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 3.6%, secondary 6.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.6% [3.6%, 3.6%] 1
Regressions ❌
(secondary)
6.4% [6.4%, 6.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.6% [3.6%, 3.6%] 1

Cycles

Results (secondary -2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 494.635s -> 485.284s (-1.89%)
Artifact size: 395.08 MiB -> 397.09 MiB (0.51%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 27, 2026
@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Nice. =D

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

pub lint_id: LintId,
pub id: HirId,
pub span: Span,
#[stable_hasher(ignore)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this correct? If the lint/id/span of the lint stays the same, but something in the labels changes, then the hash of the DynAttribute would remain unchanged

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't see a way around that, whether it's dyn Diagnostic or a callback. Although, do you see a case where a same AttributeLint is emitted on both the same HirId and span but with a different error?

this: unused_span,
other: used_span,
warning: true,
move |dcx, level| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't really like that a closure is needed here, I experimented a bit locally and this seems to be because we store the result in a query, and to call IntoDiagnostic we need ownership of this thing, which the query can't provide.

We could theoretically work around that with Steal but that seems a bit too extreme tool for such a small annoyance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe taking a diagnostic and requiring it to be Clone solves it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To be checked but it's an idea I had in mind, just didn't try it out yet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After testing out a bit, I think the current approach is the best one we can have because Box<dyn Diagnostic> is unhappy because dyn Diagnostic is not Sized (obviously) and keeping a &dyn Diagnostic creates more issues than it solves. I think it's (sadly) the best "form" we can have for now.

@rust-bors

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 1, 2026

This PR was rebased onto a different main 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.

@GuillaumeGomez
Copy link
Copy Markdown
Member Author

Fixed merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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