diff --git a/crates/ide_assists/src/utils/gen_trait_fn_body.rs b/crates/ide_assists/src/utils/gen_trait_fn_body.rs index b9c7da71b5c..eb4a23a8da3 100644 --- a/crates/ide_assists/src/utils/gen_trait_fn_body.rs +++ b/crates/ide_assists/src/utils/gen_trait_fn_body.rs @@ -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)); } diff --git a/docs/dev/style.md b/docs/dev/style.md index 92e79508b6d..e11005c5604 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -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.