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)) => {
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));
}
* `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.
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.