-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use Option.map() instead of match { Some(x) => ..., None => None } #6
Comments
There are a few patterns that could be detected:
I could find a lot more examples... |
If let is an okay alternative to map & co; one that everyone uses these days. -----Original Message----- There are a few patterns that could be detected: |
I certainly agree that it's a matter of style, not correctness. Even matching, while sometimes cumbersome is certainly not a "problem" per se. The interesting question is: Do we help people if we steer them towards map & co? If so, the lint should be as general as possible. A lint that detects the single case where someone re-implements map probably doesn't pull its weight. So where do we draw the line? Is |
Methods taking closures can be hard to read, but full blown match is also verbose. Style wise, if let ~> map >> match -----Original Message----- I certainly agree that it's a matter of style, not correctness. Even matching, while sometimes cumbersome is certainly not a "problem" per se. The interesting question is: Do we help people if we steer them towards map & co? If so, the lint should be as general as possible. |
People coming from functional languages would probably disagree here. Me, I'm fine with both
I'm not completely sure if we should suggest the following, as having two parameters, one of which may be a closure, can impede readability:
|
Yeah, but this isn't a universal style rule.
Perhaps test that y is a simple expression here? The rest sound good to me. A rough definition of simple is either an ident (well, path) a function or method call, with all paths as args. |
(Checking for simple exprs because |
Agreed. This is why I wrote I think we may want to figure out the types of the args, too, and insert as_ref` where appropriate. |
# This is the 1st commit message: Split filter_map into manual_filter_map # The commit message rust-lang#2 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#3 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#4 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#5 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#6 will be skipped: # fixup! Split filter_map into manual_filter_map
Don't know if it is best to comment here or create a new issue, but #6573 is overmatching some patterns that can't be converted to a let base_url = match args.base_url {
Some(base_url) => Some(Url::parse(&base_url)?),
_ => None,
}; be refactored to: let base_url = args.base_url.map(|base_url| Url::parse(&base_url)?); Which doesn't work because of the result unwrap, and there is no easy way to refactor this as a map and preserve the result unwrapping in the containing function. |
We can do this whenever there is no unusual flow in the first branch, which I think shouldn't be too difficult to detect.
The text was updated successfully, but these errors were encountered: