-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New Lint: Manual Flatten #6646
New Lint: Manual Flatten #6646
Conversation
@camsteffen Worked to this barebone version that checks for I have a few questions I'd like to ask for help on:
Thanks a lot 🙏 |
Good start!
I'm not sure if I'm qualified as a reviewer around here 😄 but I'm glad to help you with this!
You mean for Here is a good example for what you are doing.
Sure. That method takes two Finally, I'd suggest naming the lint |
To clarify about the lint name, a for loop over |
@camsteffen The question is if you want to get qualified as a reviewer here. :) I think this is a "good-first-review" PR. If you think this PR is ready, just ping me to take a quick look and then merge it 👍 |
Sure!
Will do. |
@camsteffen Hey Cam :) Thanks for the help. I did not explain myself well (and perhaps don't understand the language well enough either). There are two scenarios from what I can see: // Scenario 1: probably a rare case
for n in vec![Some(1), Some(2), Some(3)].iter() {
if let Some(n) = n {
println!("{}", n);
}
}
// Scenario 2
let x = vec![Some(1), Some(2), Some(3)];
for n in x {
if let Some(n) = n {
println!("{}", n);
}
} For the first one, if we recommend
So my first original question was how we could know if the type for the |
Ah right, that is a little tricky. In |
@camsteffen Check out commit 005b0fd. The new lint already brought an internal improvement via dogfood 🐶 Edit: I decided to do the linting as show in the |
Add a test for I found out that you can get the |
Oh you need to suggest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor things and then it looks good! Can you rebase onto master and squash into fewer commits?
448cd8c
to
b87e189
Compare
@flip1995 ready for final review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camsteffen great first review! You missed some things, that come up in some Clippy PRs, but those are things you'll pick up with experience 😉
@nahuakang Code LGTM so far. Mostly tests are missing (that may result in some changes that need to be made).
r? @flip1995 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small things left.
(Remember to bless the tests again after those changes)
@bors r+ Thanks! |
📌 Commit 2f8a8d3 has been approved by |
…flip1995 New Lint: Manual Flatten This is a draft PR for [Issue 6564](#6564). r? `@camsteffen` - \[x] Followed [lint naming conventions][lint_naming] - \[x] Added passing UI tests (including committed `.stderr` file) - \[x] `cargo test` passes locally - \[x] Executed `cargo dev update_lints` - \[x] Added lint documentation - \[x] Run `cargo dev fmt` --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: Add new lint `manual_flatten` to check for loops over a single `if let` expression with `Result` or `Option`.
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
@flip1995 @camsteffen Thank you both so much for your patience and help! |
This is a draft PR for Issue 6564.
r? @camsteffen
.stderr
file)cargo test
passes locallycargo dev update_lints
cargo dev fmt
Please write a short comment explaining your change (or "none" for internal only changes)
changelog: Add new lint [
manual_flatten
] to check for loops over a singleif let
expression withResult
orOption
.