Skip to content

Commit ffe4352

Browse files
committed
styling fixes
1 parent 683de87 commit ffe4352

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

crates/ide_assists/src/handlers/merge_match_arms.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::TypeInfo;
22
use std::{collections::HashMap, iter::successors};
33
use syntax::{
44
algo::neighbor,
5-
ast::{self, AstNode, HasName, MatchArm, Pat},
5+
ast::{self, AstNode, HasName},
66
Direction,
77
};
88

@@ -90,7 +90,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
9090
)
9191
}
9292

93-
fn contains_placeholder(a: &MatchArm) -> bool {
93+
fn contains_placeholder(a: &ast::MatchArm) -> bool {
9494
matches!(a.pat(), Some(ast::Pat::WildcardPat(..)))
9595
}
9696

@@ -101,54 +101,55 @@ fn are_same_types(
101101
) -> bool {
102102
let arm_types = get_arm_types(&ctx, &arm);
103103
for (other_arm_type_name, other_arm_type) in arm_types {
104-
if let (Some(Some(current_arm_type)), Some(other_arm_type)) =
105-
(current_arm_types.get(&other_arm_type_name), other_arm_type)
106-
{
107-
if other_arm_type.original != current_arm_type.original {
108-
return false;
104+
match (current_arm_types.get(&other_arm_type_name), other_arm_type) {
105+
(Some(Some(current_arm_type)), Some(other_arm_type))
106+
if other_arm_type.original == current_arm_type.original =>
107+
{
108+
()
109109
}
110-
} else {
111-
// No corresponding field found
112-
return false;
110+
_ => return false,
113111
}
114112
}
115113

116-
return true;
114+
true
117115
}
118116

119-
fn get_arm_types(context: &AssistContext, arm: &MatchArm) -> HashMap<String, Option<TypeInfo>> {
117+
fn get_arm_types(
118+
context: &AssistContext,
119+
arm: &ast::MatchArm,
120+
) -> HashMap<String, Option<TypeInfo>> {
120121
let mut mapping: HashMap<String, Option<TypeInfo>> = HashMap::new();
121122

122123
fn recurse(
123-
pat: &Option<Pat>,
124124
map: &mut HashMap<String, Option<TypeInfo>>,
125125
ctx: &AssistContext,
126+
pat: &Option<ast::Pat>,
126127
) {
127128
if let Some(local_pat) = pat {
128129
match pat {
129130
Some(ast::Pat::TupleStructPat(tuple)) => {
130131
for field in tuple.fields() {
131-
recurse(&Some(field), map, ctx);
132+
recurse(map, ctx, &Some(field));
132133
}
133134
}
134135
Some(ast::Pat::TuplePat(tuple)) => {
135136
for field in tuple.fields() {
136-
recurse(&Some(field), map, ctx);
137+
recurse(map, ctx, &Some(field));
137138
}
138139
}
139140
Some(ast::Pat::RecordPat(record)) => {
140141
if let Some(field_list) = record.record_pat_field_list() {
141142
for field in field_list.fields() {
142-
recurse(&field.pat(), map, ctx);
143+
recurse(map, ctx, &field.pat());
143144
}
144145
}
145146
}
146147
Some(ast::Pat::ParenPat(parentheses)) => {
147-
recurse(&parentheses.pat(), map, ctx);
148+
recurse(map, ctx, &parentheses.pat());
148149
}
149150
Some(ast::Pat::SlicePat(slice)) => {
150151
for slice_pat in slice.pats() {
151-
recurse(&Some(slice_pat), map, ctx);
152+
recurse(map, ctx, &Some(slice_pat));
152153
}
153154
}
154155
Some(ast::Pat::IdentPat(ident_pat)) => {
@@ -162,8 +163,8 @@ fn get_arm_types(context: &AssistContext, arm: &MatchArm) -> HashMap<String, Opt
162163
}
163164
}
164165

165-
recurse(&arm.pat(), &mut mapping, &context);
166-
return mapping;
166+
recurse(&mut mapping, &context, &arm.pat());
167+
mapping
167168
}
168169

169170
#[cfg(test)]
@@ -327,7 +328,8 @@ fn main() {
327328
fn merge_match_arms_different_type() {
328329
check_assist_not_applicable(
329330
merge_match_arms,
330-
r#"//- minicore: result
331+
r#"
332+
//- minicore: result
331333
fn func() {
332334
match Result::<f64, f32>::Ok(0f64) {
333335
Ok(x) => $0x.classify(),
@@ -342,7 +344,8 @@ fn func() {
342344
fn merge_match_arms_different_type_multiple_fields() {
343345
check_assist_not_applicable(
344346
merge_match_arms,
345-
r#"//- minicore: result
347+
r#"
348+
//- minicore: result
346349
fn func() {
347350
match Result::<(f64, f64), (f32, f32)>::Ok((0f64, 0f64)) {
348351
Ok(x) => $0x.1.classify(),
@@ -357,7 +360,8 @@ fn func() {
357360
fn merge_match_arms_same_type_multiple_fields() {
358361
check_assist(
359362
merge_match_arms,
360-
r#"//- minicore: result
363+
r#"
364+
//- minicore: result
361365
fn func() {
362366
match Result::<(f64, f64), (f64, f64)>::Ok((0f64, 0f64)) {
363367
Ok(x) => $0x.1.classify(),
@@ -437,7 +441,8 @@ fn func(e: MyEnum) {
437441
fn merge_match_arms_same_type_different_number_of_fields() {
438442
check_assist_not_applicable(
439443
merge_match_arms,
440-
r#"//- minicore: result
444+
r#"
445+
//- minicore: result
441446
fn func() {
442447
match Result::<(f64, f64, f64), (f64, f64)>::Ok((0f64, 0f64, 0f64)) {
443448
Ok(x) => $0x.1.classify(),

0 commit comments

Comments
 (0)