diff options
Diffstat (limited to 'docs/dev')
-rw-r--r-- | docs/dev/style.md | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index c4eb7bc7a..e4a1672ca 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -787,6 +787,27 @@ assert!(0 > x); | |||
787 | 787 | ||
788 | **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). |
789 | 789 | ||
790 | ## If-let | ||
791 | |||
792 | Avoid `if let ... { } else { }` construct, use `match` instead. | ||
793 | |||
794 | ```rust | ||
795 | // GOOD | ||
796 | match ctx.expected_type.as_ref() { | ||
797 | Some(expected_type) => completion_ty == expected_type && !expected_type.is_unit(), | ||
798 | None => false, | ||
799 | } | ||
800 | |||
801 | // BAD | ||
802 | if let Some(expected_type) = ctx.expected_type.as_ref() { | ||
803 | completion_ty == expected_type && !expected_type.is_unit() | ||
804 | } else { | ||
805 | false | ||
806 | } | ||
807 | ``` | ||
808 | |||
809 | **Rational:** `match` is almost always more compact. | ||
810 | The `else` branch can get a more precise pattern: `None` or `Err(_)` instead of `_`. | ||
790 | 811 | ||
791 | ## Token names | 812 | ## Token names |
792 | 813 | ||