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

Merge single_call_fn post-crate visitor into lint pass #12256

Merged
merged 1 commit into from
Feb 25, 2024

Conversation

y21
Copy link
Member

@y21 y21 commented Feb 10, 2024

The single_call_fn lint worked by first collecting a list of function definitions in the lint pass, then populating the list of uses for each function in a second visitor after the crate is checked.
Doing another pass through the crate shouldn't be needed, and we should be able to do it in the same lint pass, by looking for path references to functions only and then processing them post-crate.

Other changes:

  • FxHashMap -> FxIndexMap so that we emit warnings in a consistent order, as we see them (making the diff a bit confusing to look at, because warnings were moved around)
  • no longer storing a Vec<Span> per function: an enum representing "seen once" or "seen more than once" should be enough (only the first element is used later)
  • "used here" help is now a note

I also noticed that it lints on trait methods with a default implementation, but not on regular trait methods without a body (because that's what check_fn does). I'm not sure if that's useful though, maybe we shouldn't lint trait methods at all? It's not like you can avoid it sometimes (but then again it's a restriction lint). Either way, I left the behavior where it was before so that there are no functional changes made in this PR and it's purely a refactor. I can change it though

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2024

r? @llogiq

rustbot has assigned @llogiq.
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 Feb 10, 2024
@bors
Copy link
Contributor

bors commented Feb 19, 2024

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

@llogiq
Copy link
Contributor

llogiq commented Feb 23, 2024

Looks good, r=me after a rebase.

@y21 y21 force-pushed the single_call_fn_rm_visitor branch from 8852748 to 9a56153 Compare February 25, 2024 18:32
@y21
Copy link
Member Author

y21 commented Feb 25, 2024

Rebased. @bors r=llogiq

@bors
Copy link
Contributor

bors commented Feb 25, 2024

📌 Commit 9a56153 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 25, 2024

⌛ Testing commit 9a56153 with merge f7fa803...

bors added a commit that referenced this pull request Feb 25, 2024
Merge `single_call_fn` post-crate visitor into lint pass

The `single_call_fn` lint worked by first collecting a list of function definitions in the lint pass, then populating the list of uses for each function in a second visitor after the crate is checked.
Doing another pass through the crate shouldn't be needed, and we should be able to do it in the same lint pass, by looking for path references to functions only and then processing them post-crate.

Other changes:
- `FxHashMap` -> `FxIndexMap` so that we emit warnings in a consistent order, as we see them (making the diff a bit confusing to look at, because warnings were moved around)
- no longer storing a `Vec<Span>` per function: an enum representing "seen once" or "seen more than once" should be enough (only the first element is used later)
- "used here" help is now a note

I also noticed that it lints on trait methods with a default implementation, but not on regular trait methods without a body (because that's what `check_fn` does). I'm not sure if that's useful though, maybe we shouldn't lint trait methods at all? It's not like you can avoid it sometimes (but then again it's a restriction lint). Either way, I left the behavior where it was before so that there are no functional changes made in this PR and it's purely a refactor. I can change it though

changelog: none
@bors
Copy link
Contributor

bors commented Feb 25, 2024

💔 Test failed - checks-action_test

@y21
Copy link
Member Author

y21 commented Feb 25, 2024

Spurious probably
@bors retry

@bors
Copy link
Contributor

bors commented Feb 25, 2024

⌛ Testing commit 9a56153 with merge 7353bd0...

@bors
Copy link
Contributor

bors commented Feb 25, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 7353bd0 to master...

@bors bors merged commit 7353bd0 into rust-lang:master Feb 25, 2024
5 checks passed
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.

4 participants