Skip to content

Commit d72f7cf

Browse files
committed
internal: add => () rule; emphasize n_items rule
1 parent 1567bbb commit d72f7cf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

crates/ide_assists/src/utils/gen_trait_fn_body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
439439
let eq_check =
440440
make::expr_bin_op(lhs, BinaryOp::CmpOp(CmpOp::Eq { negated: false }), rhs);
441441

442-
let mut case_count = 0;
442+
let mut n_cases = 0;
443443
let mut arms = vec![];
444444
for variant in enum_.variant_list()?.variants() {
445-
case_count += 1;
445+
n_cases += 1;
446446
match variant.field_list() {
447447
// => (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin == r_bin,
448448
Some(ast::FieldList::RecordFieldList(list)) => {
@@ -517,7 +517,7 @@ fn gen_partial_eq(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
517517
let expr = match arms.len() {
518518
0 => eq_check,
519519
_ => {
520-
if case_count > arms.len() {
520+
if n_cases > arms.len() {
521521
let lhs = make::wildcard_pat().into();
522522
arms.push(make::match_arm(Some(lhs), None, eq_check));
523523
}

docs/dev/style.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ Default names:
849849

850850
* `res` -- "result of the function" local variable
851851
* `it` -- I don't really care about the name
852-
* `n_foo` -- number of foos
852+
* `n_foos` -- number of foos (prefer this to `foo_count`)
853853
* `foo_idx` -- index of `foo`
854854

855855
Many names in rust-analyzer conflict with keywords.
@@ -969,6 +969,26 @@ Don't use the `ref` keyword.
969969
Today, it is redundant.
970970
Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword).
971971

972+
## Empty Match Arms
973+
974+
Ues `=> (),` when a match arm is intentionally empty:
975+
976+
```rust
977+
// GOOD
978+
match result {
979+
Ok(_) => (),
980+
Err(err) => error!("{}", err),
981+
}
982+
983+
// BAD
984+
match result {
985+
Ok(_) => {}
986+
Err(err) => error!("{}", err),
987+
}
988+
```
989+
990+
**Rationale:** consistency.
991+
972992
## Functional Combinators
973993

974994
Use high order monadic combinators like `map`, `then` when they are a natural choice; don't bend the code to fit into some combinator.

0 commit comments

Comments
 (0)