From 9dafad2402426c190dbc7d134fd265f7ecedaf6b Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sat, 23 Feb 2019 14:59:41 +0200 Subject: Fix fill_match_arms not working with references --- crates/ra_assists/src/fill_match_arms.rs | 103 +++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index d8e40b4b7..005088540 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs @@ -28,6 +28,10 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx) -> Option e, + Ty::Ref(adt, _) => match *adt { + Ty::Adt { def_id: AdtDef::Enum(e), .. } => e, + _ => return None, + }, _ => return None, }; let enum_name = enum_def.name(ctx.db)?; @@ -119,6 +123,105 @@ mod tests { "#, ); } + + #[test] + fn test_fill_match_arm_refs() { + check_assist( + fill_match_arms, + r#" + enum A { + As, + Bs, + Cs(String), + Ds(String, String), + Es{x: usize, y: usize} + } + + fn foo(a: &A) { + match a<|> { + } + } + "#, + r#" + enum A { + As, + Bs, + Cs(String), + Ds(String, String), + Es{x: usize, y: usize} + } + + fn foo(a: &A) { + match <|>a { + A::As => (), + A::Bs => (), + A::Cs(_) => (), + A::Ds(_, _) => (), + A::Es{x, y} => (), + } + } + "#, + ); + + check_assist( + fill_match_arms, + r#" + enum A { + As, + Bs, + Cs(String), + Ds(String, String), + Es{x: usize, y: usize} + } + + fn foo(a: &mut A) { + match a<|> { + } + } + "#, + r#" + enum A { + As, + Bs, + Cs(String), + Ds(String, String), + Es{x: usize, y: usize} + } + + fn foo(a: &mut A) { + match <|>a { + A::As => (), + A::Bs => (), + A::Cs(_) => (), + A::Ds(_, _) => (), + A::Es{x, y} => (), + } + } + "#, + ); + + check_assist( + fill_match_arms, + r#" + enum E { X, Y} + + fn main() { + match &E::X<|> + } + "#, + r#" + enum E { X, Y} + + fn main() { + match <|>&E::X { + E::X => (), + E::Y => (), + } + } + "#, + ); + } + #[test] fn fill_match_arms_no_body() { check_assist( -- cgit v1.2.3 From 14cff98cb00bd63a6035d68f5e439dd67cb5f7e5 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sat, 23 Feb 2019 15:13:17 +0200 Subject: Simplify test_fill_match_arm_refs test cases --- crates/ra_assists/src/fill_match_arms.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 005088540..6bf6e7332 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs @@ -131,10 +131,6 @@ mod tests { r#" enum A { As, - Bs, - Cs(String), - Ds(String, String), - Es{x: usize, y: usize} } fn foo(a: &A) { @@ -145,19 +141,11 @@ mod tests { r#" enum A { As, - Bs, - Cs(String), - Ds(String, String), - Es{x: usize, y: usize} } fn foo(a: &A) { match <|>a { A::As => (), - A::Bs => (), - A::Cs(_) => (), - A::Ds(_, _) => (), - A::Es{x, y} => (), } } "#, @@ -167,10 +155,6 @@ mod tests { fill_match_arms, r#" enum A { - As, - Bs, - Cs(String), - Ds(String, String), Es{x: usize, y: usize} } @@ -181,19 +165,11 @@ mod tests { "#, r#" enum A { - As, - Bs, - Cs(String), - Ds(String, String), Es{x: usize, y: usize} } fn foo(a: &mut A) { match <|>a { - A::As => (), - A::Bs => (), - A::Cs(_) => (), - A::Ds(_, _) => (), A::Es{x, y} => (), } } -- cgit v1.2.3