about summary refs log tree commit diff
path: root/tests/ui/parser
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-08-31 00:42:58 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-08-31 00:42:58 +0000
commita7e32a5319f82c19f7c8024efd3afcc1825fa5e2 (patch)
tree63e7a401a8955086e9a644d4adc0cf4d0d77f851 /tests/ui/parser
parentfe55364329579d361b1ab565728bc033a7dba07e (diff)
downloadrust-a7e32a5319f82c19f7c8024efd3afcc1825fa5e2.tar.gz
rust-a7e32a5319f82c19f7c8024efd3afcc1825fa5e2.zip
Provide suggestion when encountering `match () { () => 1 } + match () { () => 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.
Diffstat (limited to 'tests/ui/parser')
-rw-r--r--tests/ui/parser/expr-as-stmt.stderr13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/ui/parser/expr-as-stmt.stderr b/tests/ui/parser/expr-as-stmt.stderr
index 577c3455a71..562162ef394 100644
--- a/tests/ui/parser/expr-as-stmt.stderr
+++ b/tests/ui/parser/expr-as-stmt.stderr
@@ -227,9 +227,16 @@ error[E0308]: mismatched types
   --> $DIR/expr-as-stmt.rs:69:5
    |
 LL |     match () { () => 1 } + match () { () => 1 }
-   |     ^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here
-   |     |
-   |     expected `()`, found integer
+   |     ^^^^^^^^^^^^^^^^^^^^ 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 }
+   |     +                    +
 
 error[E0308]: mismatched types
   --> $DIR/expr-as-stmt.rs:75:14