We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Find patterns like
pub fn a(s: Option<String>) -> usize { match s { Some(string) => string.len(), None => 1, } }
and suggest to use map_or instead:
map_or
pub fn a(s: Option<String>) -> usize { s.map_or(1, |string| string.len()) }
We might need to consider restricting such a lint to simple matches that don't have a lot of "stuff going on"
map_or_match? matching_map_or? mmh
style
for simple matches, this reduces lines from 4 to 1, and I think it's a bit easier to grasp what is going on if you are familiar with map_or.
🤷
We might want to bail out on matches where a single arm spans several lines.
Could be written as:
The text was updated successfully, but these errors were encountered:
Just a note for anyone taking this. There is option_if_let_some_else_none which covers this only for if let ... else ....
option_if_let_some_else_none
if let ... else ...
Sorry, something went wrong.
Seems like this hasn't been fixed yet... @rustbot claim
87b3afc
J-ZhengLi
Successfully merging a pull request may close this issue.
What it does
Find patterns like
and suggest to use
map_or
instead:We might need to consider restricting such a lint to simple matches that don't have a lot of "stuff going on"
Lint Name
map_or_match? matching_map_or? mmh
Category
style
Advantage
for simple matches, this reduces lines from 4 to 1, and I think it's a bit easier to grasp what is going on if you are familiar with
map_or
.Drawbacks
🤷
We might want to bail out on matches where a single arm spans several lines.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: