aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/fill_match_arms.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs
index d8e40b4b7..6bf6e7332 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<impl HirDatabase>) -> Option<As
28 let match_expr_ty = infer_result[node_expr].clone(); 28 let match_expr_ty = infer_result[node_expr].clone();
29 let enum_def = match match_expr_ty { 29 let enum_def = match match_expr_ty {
30 Ty::Adt { def_id: AdtDef::Enum(e), .. } => e, 30 Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,
31 Ty::Ref(adt, _) => match *adt {
32 Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,
33 _ => return None,
34 },
31 _ => return None, 35 _ => return None,
32 }; 36 };
33 let enum_name = enum_def.name(ctx.db)?; 37 let enum_name = enum_def.name(ctx.db)?;
@@ -119,6 +123,81 @@ mod tests {
119 "#, 123 "#,
120 ); 124 );
121 } 125 }
126
127 #[test]
128 fn test_fill_match_arm_refs() {
129 check_assist(
130 fill_match_arms,
131 r#"
132 enum A {
133 As,
134 }
135
136 fn foo(a: &A) {
137 match a<|> {
138 }
139 }
140 "#,
141 r#"
142 enum A {
143 As,
144 }
145
146 fn foo(a: &A) {
147 match <|>a {
148 A::As => (),
149 }
150 }
151 "#,
152 );
153
154 check_assist(
155 fill_match_arms,
156 r#"
157 enum A {
158 Es{x: usize, y: usize}
159 }
160
161 fn foo(a: &mut A) {
162 match a<|> {
163 }
164 }
165 "#,
166 r#"
167 enum A {
168 Es{x: usize, y: usize}
169 }
170
171 fn foo(a: &mut A) {
172 match <|>a {
173 A::Es{x, y} => (),
174 }
175 }
176 "#,
177 );
178
179 check_assist(
180 fill_match_arms,
181 r#"
182 enum E { X, Y}
183
184 fn main() {
185 match &E::X<|>
186 }
187 "#,
188 r#"
189 enum E { X, Y}
190
191 fn main() {
192 match <|>&E::X {
193 E::X => (),
194 E::Y => (),
195 }
196 }
197 "#,
198 );
199 }
200
122 #[test] 201 #[test]
123 fn fill_match_arms_no_body() { 202 fn fill_match_arms_no_body() {
124 check_assist( 203 check_assist(