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

Lint nested binary operations and handle field projections in eager_transmute #12031

Merged
merged 2 commits into from Jan 3, 2024

Conversation

y21
Copy link
Member

@y21 y21 commented Dec 27, 2023

This PR makes the lint a bit stronger. Previously it would only lint (x < 4).then_some(transmute(x)) (that is, a single binary op in the condition). With this change, it understands:

  • multiple, nested binary ops: (x < 4 && x > 1).then_some(...)
  • local references with projections: (x.field < 4 && x.field > 1).then_some(transmute(x.field))

changelog: [eager_transmute]: lint nested binary operations and look through field/array accesses

r? llogiq (since you reviewed my initial PR #11981, I figured you have the most context here, sorry if you are too busy with other PRs, feel free to reassign to someone else then)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 27, 2023
@y21
Copy link
Member Author

y21 commented Dec 28, 2023

It now also catches contains calls on ranges with the last commit, e.g. (1..=3).contains(&x).then_some(transmute(x)), since that's another common way of checking if an integer is within a range

@llogiq
Copy link
Contributor

llogiq commented Jan 3, 2024

Thank you! Implementations + tests look good.

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

📌 Commit 6c28f07 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

⌛ Testing commit 6c28f07 with merge ebf5c1a...

@bors
Copy link
Collaborator

bors commented Jan 3, 2024

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

@bors bors merged commit ebf5c1a into rust-lang:master Jan 3, 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.

None yet

4 participants