-
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 incorrect suggestions related to parentheses in needless_return
#14094
Conversation
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
f3de5a5
to
174b63c
Compare
174b63c
to
2d906f4
Compare
Rebased. |
2d906f4
to
304782e
Compare
Rebased. |
@Alexendoo Should I do a reassign? (I pinged you because it's been over 2 weeks) |
r? clippy |
r? @Manishearth |
r? @samueltardieu since he started reviewing |
Ah, I thought Samuel could approve but not have the privilege to merge. |
He's clippy-contributors, I can merge once he's done. |
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 am not sure this is the right fix, as I don't think that the problem lies in returns.rs
. Moreover, fixing it this way removes an explanatory message "and wrap the sequence with parentheses".
I think that you would obtain a better result by fixing clippy_utils::binary_expr_needs_parentheses()
. I have the impression that you can add a condition to the match
of the inner contains_block()
function to cover the problematic cases:
ExprKind::Cast(lhs, _) => contains_block(lhs, true),
Doing so while letting return.rs
untouched seems to pass your new tests just fine, while keeping the explanatory wrapping message when appropriate.
WDYT?
304782e
to
1cd7022
Compare
@samueltardieu Sorry for the late reply. Certainly removing |
@Manishearth This now looks good to me, feel free to merge as you please. |
@Manishearth Could you take a look at this when you have some time? |
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.
👍
close #12157
needless_return
sometimes makes incorrect suggestions by omitting necessary enclosing parentheses. This PR resolves the issue by usingclippy_utils::sugg::Sugg
.changelog: [
needless_return
]: now makes correct suggestions which require enclosing parentheses