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

Manually fulfill lint expectations for all unsafe blocks with metavars #14501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

y21
Copy link
Member

@y21 y21 commented Mar 29, 2025

Fixes #14488

Context: the macro_metavars_in_unsafe lint looks for unsafe blocks with a macro span that then contain expressions with a root context span (which means that it is a macro with an unsafe block expanding a metavariable inside). In order to avoid emitting a warning for every single macro invocation, it will deduplicate the unsafe blocks by the span in the macro.

This leads to the linked issue where because of the deduplicating and removing unsafe blocks that all belong to the same unsafe block in the macro, only one of the unsafe blocks will actually have its lint expectation fulfilled. This PR fixes that by manually fulfilling all of the unsafe blocks from all expansions before deduplicating them.

changelog: [macro_metavars_in_unsafe]: fix unfulfilled #[expect] if macro is invoked multiple times

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 29, 2025
Copy link
Contributor

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Neat

@blyxyas
Copy link
Member

blyxyas commented Mar 31, 2025

Wouldn't this also affect to any lint that apply to macros? I'm not sure if there are more, but it may add more value to modify behaviour upstream?

For now, as I think there aren't any other lints affecting to macro_rules! declarations, we can accept this, but if other lints start to lint in macros, we may be interested in fixing this in the expectation lint behaviour handler in upstream.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expect(clippy::macro_metavars_in_unsafe) only works once
4 participants