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

Improve pattern printing for manual_let_else #10797

Merged
merged 2 commits into from
May 27, 2023

Conversation

est31
Copy link
Member

@est31 est31 commented May 18, 2023

  • Address a formatting issue pointed out in https://github.com/rust-lang/rust-clippy/pull/10175/files#r1137091002
  • Replace variables inside | patterns in the if let: let v = if let V::A(v) | V::B(v) = v { v } else ...
  • Support nested patterns: let v = if let Ok(Ok(Ok(v))) = v { v } else ...
  • Support tuple structs with more than one arg: let v = V::W(v, _) = v { v } else ...; note that more than one capture is still not supported, so it bails for let (v, w) = if let E::F(vi, wi) = x { (vi, wi)}
  • Correctly handle .. in tuple struct patterns: let v = V::X(v, ..) = v { v } else ...
  • Followed lint naming conventions
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

changelog: [manual_let_else]: improve variable name in suggestions

Closes #10431 as this PR is adding a test for the mut case.

@rustbot
Copy link
Collaborator

rustbot commented May 18, 2023

r? @llogiq

(rustbot has picked a reviewer for you, use r? to override)

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

est31 commented May 18, 2023

cc @giraffate

* Replace variables inside | patterns in the if let: let v = if let V::A(v) | V::B(v) = v { v } else ...
* Support nested patterns: let v = if let Ok(Ok(Ok(v))) = v { v } else ...
* Support tuple structs with more than one arg: let v = V::W(v, _) = v { v } else ...
* Correctly handle .. in tuple struct patterns: let v = V::X(v, ..) = v { v } else ...
@llogiq
Copy link
Contributor

llogiq commented May 27, 2023

Great improvement! Thank you!

@bors r+

@bors
Copy link
Collaborator

bors commented May 27, 2023

📌 Commit ef38662 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 27, 2023

⌛ Testing commit ef38662 with merge dc17e73...

@bors
Copy link
Collaborator

bors commented May 27, 2023

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

@bors bors merged commit dc17e73 into rust-lang:master May 27, 2023
bors added a commit that referenced this pull request Jun 3, 2023
manual_let_else: support struct patterns

This adds upon the improvements of #10797 and:

* Only prints `()` around `Or` patterns at the top level (fixing a regression of #10797)
* Supports multi-binding patterns: `let (u, v) = if let (Some(u_i), Ok(v_i)) = ex { (u_i, v_i) } else ...`
* Traverses through tuple patterns: `let v = if let (Some(v), None) = ex { v } else ...`
* Supports struct patterns: `let v = if let S { v, w, } = ex { (v, w) } else ...`

```
changelog: [`manual_let_else`]: improve pattern printing to support struct patterns
```

fixes #10708
fixes #10424
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.

[manual_let_else] does not copy mut modifier
4 participants