mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Clarify comparison rule
This commit is contained in:
parent
0ce539ec96
commit
e15621482c
1 changed files with 7 additions and 1 deletions
|
@ -769,14 +769,20 @@ fn foo() -> Option<Bar> {
|
||||||
|
|
||||||
## Comparisons
|
## Comparisons
|
||||||
|
|
||||||
Use `<`/`<=`, avoid `>`/`>=`.
|
When doing multiple comparisons use `<`/`<=`, avoid `>`/`>=`.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// GOOD
|
// GOOD
|
||||||
assert!(lo <= x && x <= hi);
|
assert!(lo <= x && x <= hi);
|
||||||
|
assert!(r1 < l2 || r2 < l1);
|
||||||
|
assert!(x < y);
|
||||||
|
assert!(x > 0);
|
||||||
|
|
||||||
// BAD
|
// BAD
|
||||||
assert!(x >= lo && x <= hi>);
|
assert!(x >= lo && x <= hi>);
|
||||||
|
assert!(r1 < l2 || l1 > r2);
|
||||||
|
assert!(y > x);
|
||||||
|
assert!(0 > x);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line).
|
**Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line).
|
||||||
|
|
Loading…
Reference in a new issue