Closed
Description
Range expressions have a lower precedence than let expression. e.g.
fn main() {
if let x = (0..1) {}
}
warning: unnecessary parentheses around `let` scrutinee expression
--> src/main.rs:2:16
|
2 | if let x = (0..1) {}
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
2 - if let x = (0..1) {}
2 + if let x = 0..1 {}
|
Not using the parenthesis as suggested
fn main() {
if let x = 0..1 {}
}
error: expected expression, found `let` statement
--> src/main.rs:2:8
|
2 | if let x = 0..1 {}
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
It would be better if let
expressions just had a lower precedence, but that wouldn't be compatible with the fact the ranges are also lower than &&
and ||
. The following:
fn main() {
println!("{:?}", true && false .. false || true);
}
Prints false..true
.
Tested on nightly-2024-02-13