Closed
Description
Code
fn main() {
let x = 5 > 2 ? 3 : 1;
}
Current output
Compiling rust-playground v0.1.0 (/Users/Jens.Hausdorf/dev/rust-playground)
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `3`
--> src/main.rs:2:21
|
2 | let x = 5 > 2 ? 3 : 1;
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: could not compile `rust-playground` (bin "rust-playground") due to previous error
Desired output
Compiling rust-playground v0.1.0 (/Users/Jens.Hausdorf/dev/rust-playground)
error: should have used inline if-expression instead
--> src/main.rs:2:21
|
2 | let x = 5 > 2 ? 3 : 1;
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
help: consider changing this to use if-expression
|
2 | let x = if 5 > 2 { 3 } else { 1 };
|
error: could not compile `rust-playground` (bin "rust-playground") due to previous error
Rationale and extra context
New rustaceans might expect that Rust has the ternary operator.
Other cases
No response
Anything else?
No response