Skip to content

while_let_loop: Include let assignment in suggestion #14756

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

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

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented May 8, 2025

Placeholders are still given for the content of the whole block. However, if the result of the original if let or match expression was assigned, the assignment is reflected in the suggestion.

No-op assignments (let x = x;) are skipped though, unless they contain an explicit type which might help the compiler (let x: u32 = x; is kept).

Closes #362

changelog: [while_let_loop]: include let assignment in suggestion

This is shorter, and also avoids overloading the `peel_blocks()` from
`clippy_utils` with different semantics.
@rustbot
Copy link
Collaborator

rustbot commented May 8, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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 May 8, 2025
help: try
|
LL ~ while let Some(ele) = iter.next() {
LL + let _ = ele;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably also ignore these as they're no-ops (doesn't even read from ele).

Placeholders are still given for the content of the whole block. However, if the
result of the original `if let` or `match` expression was assigned, the
assignment is reflected in the suggestion.

No-op assignments (`let x = x;`) are skipped though, unless they contain an
explicit type which might help the compiler (`let x: u32 = x;` is kept).
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.

while_let_loop fails to account for lifetimes
3 participants