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