7858: Clarify comparison rule r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-03-03 08:23:38 +00:00 committed by GitHub
commit 2b22fc929a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -769,14 +769,20 @@ fn foo() -> Option<Bar> {
## Comparisons
Use `<`/`<=`, avoid `>`/`>=`.
When doing multiple comparisons use `<`/`<=`, avoid `>`/`>=`.
```rust
// GOOD
assert!(lo <= x && x <= hi);
assert!(r1 < l2 || r2 < l1);
assert!(x < y);
assert!(x > 0);
// BAD
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).