aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/fill_match_arms.rs103
1 files changed, 103 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..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<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,105 @@ 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 Bs,
135 Cs(String),
136 Ds(String, String),
137 Es{x: usize, y: usize}
138 }
139
140 fn foo(a: &A) {
141 match a<|> {
142 }
143 }
144 "#,
145 r#"
146 enum A {
147 As,
148 Bs,
149 Cs(String),
150 Ds(String, String),
151 Es{x: usize, y: usize}
152 }
153
154 fn foo(a: &A) {
155 match <|>a {
156 A::As => (),
157 A::Bs => (),
158 A::Cs(_) => (),
159 A::Ds(_, _) => (),
160 A::Es{x, y} => (),
161 }
162 }
163 "#,
164 );
165
166 check_assist(
167 fill_match_arms,
168 r#"
169 enum A {
170 As,
171 Bs,
172 Cs(String),
173 Ds(String, String),
174 Es{x: usize, y: usize}
175 }
176
177 fn foo(a: &mut A) {
178 match a<|> {
179 }
180 }
181 "#,
182 r#"
183 enum A {
184 As,
185 Bs,
186 Cs(String),
187 Ds(String, String),
188 Es{x: usize, y: usize}
189 }
190
191 fn foo(a: &mut A) {
192 match <|>a {
193 A::As => (),
194 A::Bs => (),
195 A::Cs(_) => (),
196 A::Ds(_, _) => (),
197 A::Es{x, y} => (),
198 }
199 }
200 "#,
201 );
202
203 check_assist(
204 fill_match_arms,
205 r#"
206 enum E { X, Y}
207
208 fn main() {
209 match &E::X<|>
210 }
211 "#,
212 r#"
213 enum E { X, Y}
214
215 fn main() {
216 match <|>&E::X {
217 E::X => (),
218 E::Y => (),
219 }
220 }
221 "#,
222 );
223 }
224
122 #[test] 225 #[test]
123 fn fill_match_arms_no_body() { 226 fn fill_match_arms_no_body() {
124 check_assist( 227 check_assist(