Skip to content

Pretty-print parenthesis around binary in postfix match - #124269

Merged
bors merged 1 commit into
rust-lang:masterfrom
scrabsha:sasha/fix-124206
Apr 29, 2024
Merged

Pretty-print parenthesis around binary in postfix match#124269
bors merged 1 commit into
rust-lang:masterfrom
scrabsha:sasha/fix-124206

Conversation

@scrabsha

Copy link
Copy Markdown
Contributor

Fixes#124206.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @michaelwoerister

rustbot has assigned @michaelwoerister.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 22, 2024
Comment threadcompiler/rustc_ast_pretty/src/pprust/state/expr.rs Outdated
@RossSmyth

Copy link
Copy Markdown
Contributor

Could you please either give the test name something descriptive about what the test tests (idk pfix-match-paren or something) or make a new directory for postfix match within the pretty directory. Adding tests with issue numbers, while common, makes maintenance frustrating.

@scrabsha
scrabshaforce-pushed the sasha/fix-124206 branch 2 times, most recently from 027d6f0 to 6d6bc93CompareApril 22, 2024 18:29
@scrabsha

Copy link
Copy Markdown
ContributorAuthor

Could you please either give the test name something descriptive about what the test tests (idk pfix-match-paren or something) or make a new directory for postfix match within the pretty directory. Adding tests with issue numbers, while common, makes maintenance frustrating.

I mkdired tests/pretty/postfix-match and moved every postfix-match-related test in it. Thanks for the suggestion!

Comment on lines +16 to +27
(
{ 1 } + 1).match {
_ => {}
};

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect. Is it an issue in my code or in the pretty printer?

@dtolnaydtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to cause double parens to be put around cases like repro!(1 + Struct {}). ((1 + Struct {})).match { _ => {} }

In general print_expr_as_cond is not a correct thing to be using here. That is for syntactic positions where a { is ambiguous between being a part of the matched expression / if condition / while condition, vs being the body for the match/if/while. It isn't applicable to postfix match.

Postfix match needs to be printed like very other expression kind containing ., such as field accesses and method call expressions and postfix await.

@dtolnaydtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2024
Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
@scrabsha

Copy link
Copy Markdown
ContributorAuthor

@dtolnay I modified my changes according to your comment and added your example in the test suite. Thanks!

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2024
@scrabsha
scrabsha requested a review from dtolnayApril 29, 2024 09:39

@dtolnaydtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Apr 29, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit c8ff8a4 has been approved by dtolnay

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2024
@jieyouxujieyouxu mentioned this pull request Apr 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2024
Rollup of 7 pull requests
Successful merges:
- rust-lang#124269 (Pretty-print parenthesis around binary in postfix match)
- rust-lang#124415 (Use probes more aggressively in new solver)
- rust-lang#124475 (Remove direct dependencies on lazy_static, once_cell and byteorder)
- rust-lang#124484 (Fixrust-lang#124478 - offset_of! returns a temporary)
- rust-lang#124504 (Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout)
- rust-lang#124508 (coverage: Avoid hard-coded values when visiting logical ops)
- rust-lang#124522 ([Refactor] Rename `Lint` and `LintGroup`'s `is_loaded` to `is_externally_loaded` )
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit f1c53da into rust-lang:masterApr 29, 2024
@rustbotrustbot added this to the 1.80.0 milestone Apr 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2024
Rollup merge of rust-lang#124269 - scrabsha:sasha/fix-124206, r=dtolnay
Pretty-print parenthesis around binary in postfix match
Fixesrust-lang#124206.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AST pretty-printer produces invalid syntax for postfix match

7 participants

@scrabsha@rustbot@RossSmyth@dtolnay@bors@compiler-errors@michaelwoerister