diff options
| author | Jeroen Vannevel <jer_vannevel@outlook.com> | 2022-01-10 18:30:27 +0000 |
|---|---|---|
| committer | Jeroen Vannevel <jer_vannevel@outlook.com> | 2022-01-14 01:32:10 +0000 |
| commit | c52605024c2e6dfb3cc41728bd246b6073ec4998 (patch) | |
| tree | 7e2d869e9d12bef6c274706ab2870f44eee47627 | |
| parent | d8a3e51a5f4d6dcb8da269470061bfbb6b50e81f (diff) | |
| download | rust-c52605024c2e6dfb3cc41728bd246b6073ec4998.tar.gz rust-c52605024c2e6dfb3cc41728bd246b6073ec4998.zip | |
extracted function
| -rw-r--r-- | crates/ide_assists/src/handlers/merge_match_arms.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/crates/ide_assists/src/handlers/merge_match_arms.rs b/crates/ide_assists/src/handlers/merge_match_arms.rs index 5b0a66529ee..75710b138f5 100644 --- a/crates/ide_assists/src/handlers/merge_match_arms.rs +++ b/crates/ide_assists/src/handlers/merge_match_arms.rs @@ -1,4 +1,3 @@ -use hir::TypeInfo; use itertools::Itertools; use std::iter::successors; use syntax::{ @@ -53,18 +52,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option return false; } - let arm_types = get_arm_types(&ctx, &arm); - for i in 0..arm_types.len() { - let other_arm_type = &arm_types[i].as_ref(); - let current_arm_type = current_arm_types[i].as_ref(); - if let (Some(other_arm_type), Some(current_arm_type)) = - (other_arm_type, current_arm_type) - { - return &other_arm_type.original == ¤t_arm_type.original; - } - } - - true + return are_same_types(¤t_arm_types, arm, ctx); } _ => false, }) @@ -106,7 +94,24 @@ fn contains_placeholder(a: &ast::MatchArm) -> bool { matches!(a.pat(), Some(ast::Pat::WildcardPat(..))) } -fn get_arm_types(ctx: &AssistContext, arm: &ast::MatchArm) -> Vec<Option<TypeInfo>> { +fn are_same_types( + current_arm_types: &Vec<Option<hir::TypeInfo>>, + arm: &ast::MatchArm, + ctx: &AssistContext, +) -> bool { + let arm_types = get_arm_types(&ctx, &arm); + for i in 0..arm_types.len() { + let other_arm_type = &arm_types[i].as_ref(); + let current_arm_type = current_arm_types[i].as_ref(); + if let (Some(other_arm_type), Some(current_arm_type)) = (other_arm_type, current_arm_type) { + return &other_arm_type.original == ¤t_arm_type.original; + } + } + + return true; +} + +fn get_arm_types(ctx: &AssistContext, arm: &ast::MatchArm) -> Vec<Option<hir::TypeInfo>> { match arm.pat() { Some(ast::Pat::TupleStructPat(tp)) => tp .fields() |
