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

Replace in_macro usage with from_expansion #7897

Merged
merged 2 commits into from
Nov 5, 2021

Conversation

camsteffen
Copy link
Contributor

changelog: none

Generally replace in_macro(span) with span.from_expansion(). If we're just trying to avoid expanded code, this seems more appropriate because any kind of expanded code is prone to false positives. One place I did not touch is macro_use.rs. I think this lint could use a rewrite so I moved in_macro there, the only place it is still used.

@rust-highfive
Copy link

r? @flip1995

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 29, 2021
@camsteffen camsteffen force-pushed the in-macro branch 2 times, most recently from c1787f5 to a7fdeab Compare October 29, 2021 18:57
@camsteffen
Copy link
Contributor Author

Eh let's wait for the sync

@flip1995
Copy link
Member

Ah nice, so the for-loop lowering PR got merged and this will get through without test regressions? Nice! I'll make sure to include this PR in the sync-back to rustc 👍

@camsteffen
Copy link
Contributor Author

To be clear there are a few changes beyond simply replacing the function, but it's all fairly straightforward.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

Now also reviewed the other small changes.

clippy_lints/src/macro_use.rs Show resolved Hide resolved
@xFrednet
Copy link
Member

xFrednet commented Nov 4, 2021

Could you also update the Dealing with macros documentation in accordance to this change? It would be good to mention that it's generally better to use .from_expansion() 🙃

@bors
Copy link
Collaborator

bors commented Nov 4, 2021

☔ The latest upstream changes (presumably #7929) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

flip1995 commented Nov 4, 2021

I'll make sure to include this PR in the sync-back to rustc

Since this is a NFC, I decided to rather get the sync through as fast as possible, instead of trying to get this included in the sync.

@camsteffen camsteffen force-pushed the in-macro branch 3 times, most recently from 9b4d239 to 0c0416a Compare November 5, 2021 13:42
@camsteffen
Copy link
Contributor Author

Rebased. Removed some redundant in_external_macro calls. Edited the docs.

@flip1995
Copy link
Member

flip1995 commented Nov 5, 2021

Thanks! This looks good now.

About removing differing_macro_contexts: IIRC, the only thing that it does is returning span1.ctxt() != span2.ctxt(), right? So yeah, having a wrapper function for this doesn't really help complexity-wise. The question is if the implicit documentation of having this function helps. I personally don't think that it is that important, since span1.ctxt() != span2.ctxt() is already telling enough IMO. So I guess, it could be removed. But let's do this in an additional PR.

@bors r+ p=1 (codebase wide change)

@bors
Copy link
Collaborator

bors commented Nov 5, 2021

📌 Commit 5b1b6a2 has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Nov 5, 2021

⌛ Testing commit 5b1b6a2 with merge 9a60a93...

@bors
Copy link
Collaborator

bors commented Nov 5, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 9a60a93 to master...

@bors bors merged commit 9a60a93 into rust-lang:master Nov 5, 2021
bors added a commit that referenced this pull request Jan 5, 2022
Remove in_macro from clippy_utils

changelog: none

Previously done in #7897 but reverted in #8170. I'd like to keep `in_macro` out of utils because if a span is from expansion in any way (desugaring or macro), we should not proceed without understanding the nature of the expansion IMO.

r? `@llogiq`
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.

5 participants