From d8a3e51a5f4d6dcb8da269470061bfbb6b50e81f Mon Sep 17 00:00:00 2001 From: Jeroen Vannevel Date: Mon, 10 Jan 2022 18:24:36 +0000 Subject: [PATCH] added tests for multiple fields --- .../src/handlers/merge_match_arms.rs | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/crates/ide_assists/src/handlers/merge_match_arms.rs b/crates/ide_assists/src/handlers/merge_match_arms.rs index a397247e0f..5b0a66529e 100644 --- a/crates/ide_assists/src/handlers/merge_match_arms.rs +++ b/crates/ide_assists/src/handlers/merge_match_arms.rs @@ -1,6 +1,6 @@ -use std::iter::successors; use hir::TypeInfo; use itertools::Itertools; +use std::iter::successors; use syntax::{ algo::neighbor, ast::{self, AstNode}, @@ -57,7 +57,9 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option 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) { + 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; } } @@ -289,11 +291,41 @@ fn func() { "#, ); } -} -// fn func() { -// match Result::::Ok(0f64) { -// Ok(x) => x.classify(), -// Err(x) => x.classify() -// }; -// } + #[test] + fn merge_match_arms_different_type_multiple_fields() { + check_assist_not_applicable( + merge_match_arms, + r#"//- minicore: result +fn func() { + match Result::<(f64, f64), (f32, f32)>::Ok((0f64, 0f64)) { + Ok(x) => $0x.1.classify(), + Err(x) => x.1.classify() + }; +} +"#, + ); + } + + #[test] + fn merge_match_arms_same_type_multiple_fields() { + check_assist( + merge_match_arms, + r#"//- minicore: result +fn func() { + match Result::<(f64, f64), (f64, f64)>::Ok((0f64, 0f64)) { + Ok(x) => $0x.1.classify(), + Err(x) => x.1.classify() + }; +} +"#, + r#" +fn func() { + match Result::<(f64, f64), (f64, f64)>::Ok((0f64, 0f64)) { + Ok(x) | Err(x) => x.1.classify(), + }; +} +"#, + ); + } +}