diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-03 08:23:38 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-03 08:23:38 +0000 |
commit | 2b22fc929a5f13d6cddb9458b1b205f9aee60299 (patch) | |
tree | 301b97ac6d9e03f620625574c3c6038c7f83959f | |
parent | 3b507aa90fca9618ddbe0667e245ef4766aa96b5 (diff) | |
parent | e15621482c1b25dba5f4d2bf60f7546149edb6af (diff) |
Merge #7858
7858: Clarify comparison rule r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | docs/dev/style.md | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index dd71e3932..93ad98f20 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -769,14 +769,20 @@ fn foo() -> Option<Bar> { | |||
769 | 769 | ||
770 | ## Comparisons | 770 | ## Comparisons |
771 | 771 | ||
772 | Use `<`/`<=`, avoid `>`/`>=`. | 772 | When doing multiple comparisons use `<`/`<=`, avoid `>`/`>=`. |
773 | 773 | ||
774 | ```rust | 774 | ```rust |
775 | // GOOD | 775 | // GOOD |
776 | assert!(lo <= x && x <= hi); | 776 | assert!(lo <= x && x <= hi); |
777 | assert!(r1 < l2 || r2 < l1); | ||
778 | assert!(x < y); | ||
779 | assert!(x > 0); | ||
777 | 780 | ||
778 | // BAD | 781 | // BAD |
779 | assert!(x >= lo && x <= hi>); | 782 | assert!(x >= lo && x <= hi>); |
783 | assert!(r1 < l2 || l1 > r2); | ||
784 | assert!(y > x); | ||
785 | assert!(0 > x); | ||
780 | ``` | 786 | ``` |
781 | 787 | ||
782 | **Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line). | 788 | **Rationale:** Less-then comparisons are more intuitive, they correspond spatially to [real line](https://en.wikipedia.org/wiki/Real_line). |