Closed
Description
Hi,
As I understand, chaining inequality operators like <
, >
, <=
and >=
is not allowed. Yet trying to do so will ask you to add parenthesies:
fn main() {
let x = 2;
if 1 <= x <= 3 {
println!("yes");
} else {
println!("no");
}
}
Gives:
error: chained comparison operators require parentheses
--> src/main.rs:4:10
|
4 | if 1 <= x <= 3 {
| ^^^^^^^
error[E0308]: mismatched types
--> src/main.rs:4:18
|
4 | if 1 <= x <= 3 {
| ^ expected bool, found integer
|
= note: expected type `bool`
found type `{integer}`
The first error is false advice in the context of <=
. It would have been ok for ==
though.
Thanks :)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Relevant to the compiler team, which will review and decide on the PR/issue.