-
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
fix suggestion in option_map_or_none #7971
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ed4a8a
fix suggestion in option_map_or_none
togami2864 4f71ff3
add test case for option_map_or_none
togami2864 bbffe82
add reduce_unit_expression
togami2864 02e0726
fix a bug that the closure arguments are not displayed
togami2864 cd57816
add comment
togami2864 300282c
fix fmt
togami2864 0a30fdc
move the let statement out of the macro
togami2864 7605bac
resolve CI
togami2864 e34927e
add multi-line test case
togami2864 006c442
check whether stmts is empty or not in block
togami2864 8e317f5
fix suggestion message
togami2864 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think you should also remove the
Some( )
, otherwise you'll change the type fromOption<_>
toOption<Option<_>>
.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.
Is it correct that I should somehow remove
Some ( )
in this line?rust-clippy/clippy_lints/src/methods/option_map_or_none.rs
Line 54 in f51fb34
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.
Exactly. The problem here is that while this should usually be
Some(_)
which is anExprCall(..)
with a single item inargs
, it could also be any other expression that evaluates to anOption
, e.g.{ let foo = Some(bar); foo }
orfunction_returning_option()
.The right way to do this is to check if this is a
ExprKind::Call
toSome(_)
, then remove the call and use the zeroeth argument with themap
, or using the original expression withand_then
otherwise.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.
Now, I don't understand how to identify whether
Some
is in the code or not.What I did
case1:
I tried to identify it by match with
expr.kind
and write like this.But I couldn't get the path of
Some( )
inClosure
which is expected as the oneth arg inmap_or
.case2:
I tried to identify it by match with
map_arg
.rust-clippy/clippy_lints/src/methods/option_map_or_none.rs
Line 20 in f82bf47
However, the type of
map_arg
differs depending on the code you lint. (in this caseExprKind::Closure
orExprKind::Path
.)In both cases, I couldn't specify
Some()
in code.Would you have any advice? Due to my limited understanding, it is possible that my approach is fundamentally wrong.
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.
First, this is not an
ExprKind::MethodCall
, but anExprKind::Call
. The rest has been done before, e.g. inclippy_lints/src/methods/chars_cmp.rs#L22-26
.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.
Thanks.
I tried to output
expr.kind
, but it seems to be judged asExprKind::MethodCall
🤔rust-clippy/clippy_lints/src/methods/option_map_or_none.rs
Line 17 in f82bf47
Result
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.
I wasn't talking about the
.map_or(..)
call expr, but the 2nd argument, which is a closure of which you need to get theBody
first. Sorry I forgot about that.