Skip to content
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

Infrastructure for lints during attribute parsing, specifically duplicate usages of attributes #138164

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jdonszelmann
Copy link
Contributor

r? @oli-obk

Currently depends on #138060 and #138160 to merge. Those should be pretty trivial on their own. No need to review those commits in this PR.

This PR adds a new field to the diagnostics context to buffer lints which are generated during attribute parsing. They can't be emitted during attribute parsing because at that point there's no HIR yet, and early lints are already emitted.

This also adds the generic S: Stage to attribute parsers. Currently we don't emit any lints during early attribute parsing, but if we ever want to that logic will be different. That's because there we don't have hir ids yet, while at the same time still having access to node ids and early lints. Even though that logic isn't completely there in this PR (no worries, we don't use it), that's why the parameter is there.

With this PR, we also add 2 associated consts to SingleAttributeParser. Those determine what logic should be applied when finding a duplicate attribute.

@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 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2025

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 has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 7, 2025
@rustbot

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

(am aware of merge commits, was just an easy way to get those changes in before they're on master so we can run CI on this PR. will obviously remove once those changes are on master and this PR can be merged)

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the attr-parsing-lint-infra branch from b5f1130 to 9559a37 Compare March 8, 2025 19:03
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 8, 2025
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the attr-parsing-lint-infra branch from 9559a37 to d529827 Compare March 9, 2025 15:31
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the attr-parsing-lint-infra branch from d529827 to bfeed70 Compare March 9, 2025 16:08
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the attr-parsing-lint-infra branch from bfeed70 to fc63551 Compare March 9, 2025 20:08
Comment on lines +564 to +567
/// *specifically* for lints emitted during ast lowering.
/// At this point we can't get the lint level yet (doing so will cause really weird bugs).
/// So, by stuffing lints in here they can be emitted when hir is built.
hir_delayed_lints: Vec<HirDelayedLint>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is sound (wrt incremental) for lints. I think the right place would be to put them into https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OwnerInfo.html and emit them from the late lint for each owner.

&'static Lint,
HirId,
Span,
Box<dyn DynSend + for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>) + 'static>
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly this won't work, as you can't hash it for incremental

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.

4 participants