Respect parenthesized generators in has_own_parentheses#8100
Merged
charliermarsh merged 1 commit intomainfrom Oct 22, 2023
Merged
Respect parenthesized generators in has_own_parentheses#8100charliermarsh merged 1 commit intomainfrom
has_own_parentheses#8100charliermarsh merged 1 commit intomainfrom
Conversation
charliermarsh
commented
Oct 20, 2023
| pub(crate) fn is_tuple_parenthesized(tuple: &ExprTuple, source: &str) -> bool { | ||
| let Some(elt) = tuple.elts.first() else { | ||
| return false; | ||
| return true; |
Member
Author
There was a problem hiding this comment.
An empty tuple has to be parenthesized. Otherwise, it... can't exist?
charliermarsh
commented
Oct 20, 2023
| if visitor.max_precedence == OperatorPrecedence::None { | ||
| true | ||
| } else if visitor.pax_precedence_count > 1 { | ||
| } else if visitor.max_precedence_count > 1 { |
Member
Author
There was a problem hiding this comment.
I think this was a typo, but please correct me if I'm wrong.
MichaReiser
approved these changes
Oct 22, 2023
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When analyzing:
We missed that the generator expression is parenthesized, because the parentheses are part of the generator -- so
is_expression_parenthesizedreturnsFalse. We needed to take into account that generators and tuples may or may not be parenthesized when determining whether we can omit parentheses while splitting an expression.Closes #8090.
Test Plan
No changes in similarity.
Before:
After: