]> git.lizzy.rs Git - rust.git/commitdiff
internal: add => () rule; emphasize `n_items` rule
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 25 Sep 2021 11:10:25 +0000 (14:10 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 25 Sep 2021 11:10:25 +0000 (14:10 +0300)
crates/ide_assists/src/utils/gen_trait_fn_body.rs
docs/dev/style.md

index b9c7da71b5c01754d787fa1fbbacf9b6a08ca33d..eb4a23a8da334a30ab2b6ce7b1c577310e1969af 100644 (file)
@@ -439,10 +439,10 @@ fn gen_tuple_field(field_name: &String) -> ast::Pat {
             let eq_check =
                 make::expr_bin_op(lhs, BinaryOp::CmpOp(CmpOp::Eq { negated: false }), rhs);
 
-            let mut case_count = 0;
+            let mut n_cases = 0;
             let mut arms = vec![];
             for variant in enum_.variant_list()?.variants() {
-                case_count += 1;
+                n_cases += 1;
                 match variant.field_list() {
                     // => (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin == r_bin,
                     Some(ast::FieldList::RecordFieldList(list)) => {
@@ -517,7 +517,7 @@ fn gen_tuple_field(field_name: &String) -> ast::Pat {
             let expr = match arms.len() {
                 0 => eq_check,
                 _ => {
-                    if case_count > arms.len() {
+                    if n_cases > arms.len() {
                         let lhs = make::wildcard_pat().into();
                         arms.push(make::match_arm(Some(lhs), None, eq_check));
                     }
index 92e79508b6db7baf3197e73d8dcbf25f6973a023..e11005c5604ed35f9f3f3d021f1e03e9071337a5 100644 (file)
@@ -849,7 +849,7 @@ Default names:
 
 * `res` -- "result of the function" local variable
 * `it` -- I don't really care about the name
-* `n_foo` -- number of foos
+* `n_foos` -- number of foos (prefer this to `foo_count`)
 * `foo_idx` -- index of `foo`
 
 Many names in rust-analyzer conflict with keywords.
@@ -969,6 +969,26 @@ Don't use the `ref` keyword.
 Today, it is redundant.
 Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword).
 
+## Empty Match Arms
+
+Ues `=> (),` when a match arm is intentionally empty:
+
+```rust
+// GOOD
+match result {
+    Ok(_) => (),
+    Err(err) => error!("{}", err),
+}
+
+// BAD
+match result {
+    Ok(_) => {}
+    Err(err) => error!("{}", err),
+}
+```
+
+**Rationale:** consistency.
+
 ## Functional Combinators
 
 Use high order monadic combinators like `map`, `then` when they are a natural choice; don't bend the code to fit into some combinator.