-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add additional parenthesis for binary ops in pretty printer #27613
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
Conversation
Otherwise, we get (1 + 2) * 3 looking like 1 + 2 * 3
Previously it just added parentheses in excess. e.g. ((1 + 2) + 3) + 4
This just adds paren following the same cases as before
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Was failing on pretty/issue-4264.rs, due to some additional parenthesis. I assume that 'as' is left associative? |
Rather than adding this logic in three places, could you modify |
It doesn't seem much cleaner, especially with that Option, although perhaps I can do it a different way. |
Can you check the sub-expression rather than passing in the parent? |
@nrc Dropped the last patch. |
@bors: r+ |
📌 Commit 22baa46 has been approved by |
In the case where there are no paren in the AST, the pretty printer doesn't correctly print binary operations where precedence is concerned. Parenthesis may be missing due to some kind of expansion or manipulation of the AST. Example: Pretty printer prints Expr(*, Expr(+, 1, 1), 2) as 1 + 1 * 2, as opposed to (1 + 1) * 2 r? @nrc
In the case where there are no paren in the AST, the pretty printer doesn't correctly print binary operations where precedence is concerned. Parenthesis may be missing due to some kind of expansion or manipulation of the AST.
Example:
Pretty printer prints Expr(*, Expr(+, 1, 1), 2) as 1 + 1 * 2, as opposed to (1 + 1) * 2
r? @nrc