Description
When an if-else block produces a value and this is followed by an operator and this all happens inside a block, this is apparently a parsing error.
When the operator is +
, the parsing error is pointed out. When the operator is &
, the parsing error is not pointed out.
Please provide the parsing error for all operators.
Given the following code: https://play.rust-lang.org/?edition=2021&gist=55a7b19b44fc6010a33338774bef3b11
fn main() {
{ if true { 0 } else { 0 } & 0 };
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/main.rs:2:17
|
2 | { if true { 0 } else { 0 } & 0 };
| ----------^-------------
| | |
| | expected `()`, found integer
| expected this to be `()`
error[E0308]: mismatched types
--> src/main.rs:2:28
|
2 | { if true { 0 } else { 0 } & 0 };
| ---------------------^--
| | |
| | expected `()`, found integer
| expected this to be `()`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors
Ideally the output should look like the output when +
is used instead of &
:
Compiling playground v0.0.1 (/playground)
error: leading `+` is not supported
--> src/main.rs:2:32
|
2 | { if true { 0 } else { 0 } + 0 };
| ^ unexpected `+`
|
help: parentheses are required to parse this as an expression
|
2 | { (if true { 0 } else { 0 }) + 0 };
| + +
error[E0308]: mismatched types
--> src/main.rs:2:17
|
2 | { if true { 0 } else { 0 } + 0 };
| ----------^-------------
| | |
| | expected `()`, found integer
| expected this to be `()`
error[E0308]: mismatched types
--> src/main.rs:2:28
|
2 | { if true { 0 } else { 0 } + 0 };
| ---------------------^--
| | |
| | expected `()`, found integer
| expected this to be `()`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 3 previous errors
Note the added help line: parentheses are required to parse this as an expression
This explanation should be included for all operators.
Nightly has the same problem.
Stable: rustc 1.57.0 (f1edd04 2021-11-29)
Nightly: rustc 1.59.0-nightly (c5ecc15 2021-12-15) (from rustc 1.59.0-nightly (404c847 2021-12-14))