Skip to content

Commit 2b22fc9

Browse files
bors[bot]matklad
andauthored
Merge #7858
7858: Clarify comparison rule r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 3b507aa + e156214 commit 2b22fc9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/dev/style.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,14 +769,20 @@ fn foo() -> Option<Bar> {
769769

770770
## Comparisons
771771

772-
Use `<`/`<=`, avoid `>`/`>=`.
772+
When doing multiple comparisons use `<`/`<=`, avoid `>`/`>=`.
773773

774774
```rust
775775
// GOOD
776776
assert!(lo <= x && x <= hi);
777+
assert!(r1 < l2 || r2 < l1);
778+
assert!(x < y);
779+
assert!(x > 0);
777780

778781
// BAD
779782
assert!(x >= lo && x <= hi>);
783+
assert!(r1 < l2 || l1 > r2);
784+
assert!(y > x);
785+
assert!(0 > x);
780786
```
781787

782788
**Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line).

0 commit comments

Comments
 (0)