Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Suggest parentheses when match or if expression in binop is parsed as statement #146044

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

Open
estebank wants to merge 3 commits into rust-lang:master
base: master
Choose a base branch
Loading
from estebank:issue-88727

Conversation

Copy link
Contributor

@estebank estebank commented Aug 31, 2025
edited by rustbot
Loading

error[E0308]: mismatched types
 --> $DIR/expr-as-stmt.rs:81:5
 |
LL | match () { _ => true } && match () { _ => true };
 | ^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `bool`
 |
help: parentheses are required to parse this as an expression
 |
LL | (match () { _ => true }) && match () { _ => true };
 | + +

Address the common case from #88727. The original parse error is still outstanding, but the cases brought up in the thread are resolved.

... { () => 1 }`
```
error[E0308]: mismatched types
 --> $DIR/expr-as-stmt.rs:69:5
 |
LL | match () { () => 1 } + match () { () => 1 }
 | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found integer
 |
help: consider using a semicolon here
 |
LL | match () { () => 1 }; + match () { () => 1 }
 | +
help: alternatively, parentheses are required to parse this as an expression
 |
LL | (match () { () => 1 }) + match () { () => 1 }
 | + +
```
Parentheses are needed for the `match` to be unambiguously parsed as an expression and not a statement when chaining with binops that are also unops.
...expression
```
error[E0308]: mismatched types
 --> $DIR/expr-as-stmt.rs:69:5
 |
LL | match () { () => 1 } + match () { () => 1 }
 | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found integer
 |
help: parentheses are required to parse this as an expression
 |
LL | (match () { () => 1 }) + match () { () => 1 }
 | + +
```
Copy link
Collaborator

rustbot commented Aug 31, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
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

@rustbot rustbot 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 Aug 31, 2025
Copy link
Member

estebank reacted with heart emoji

```
error[E0308]: mismatched types
 --> $DIR/expr-as-stmt-2.rs:15:15
 |
LL | if true { true } else { false } && true;
 | ----------^^^^-----------------
 | | |
 | | expected `()`, found `bool`
 | expected this to be `()`
 |
help: parentheses are required to parse this as an expression
 |
LL | (if true { true } else { false }) && true;
 | + +
```
@estebank estebank changed the title (削除) Suggest parentheses when match expression in binop is parsed as statement (削除ここまで) (追記) Suggest parentheses when match or if expression in binop is parsed as statement (追記ここまで) Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Labels
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.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /