aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2020-03-24 02:23:30 +0000
committerJosh Mcguigan <[email protected]>2020-03-24 02:23:30 +0000
commit7ba934fe5866e6aedd8d18e95f8c54e17e18ea51 (patch)
tree75f5ed463bcced84e4644b96ec080fdf7972ac26
parentf9494f114798f66b5f2174cf518a2951a82571d3 (diff)
fill match arms with empty block rather than unit tuple
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs4
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs90
-rw-r--r--crates/ra_syntax/src/ast/make.rs3
3 files changed, 50 insertions, 47 deletions
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index aef6793e8..62dcb3808 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -275,8 +275,8 @@ enum Action { Move { distance: u32 }, Stop }
275 275
276fn handle(action: Action) { 276fn handle(action: Action) {
277 match action { 277 match action {
278 Action::Move { distance } => (), 278 Action::Move { distance } => {}
279 Action::Stop => (), 279 Action::Stop => {}
280 } 280 }
281} 281}
282"#####, 282"#####,
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 7463b2af7..a7c315ca1 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -30,8 +30,8 @@ use ast::{MatchArm, Pat};
30// 30//
31// fn handle(action: Action) { 31// fn handle(action: Action) {
32// match action { 32// match action {
33// Action::Move { distance } => (), 33// Action::Move { distance } => {}
34// Action::Stop => (), 34// Action::Stop => {}
35// } 35// }
36// } 36// }
37// ``` 37// ```
@@ -57,7 +57,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
57 .into_iter() 57 .into_iter()
58 .filter_map(|variant| build_pat(ctx.db, module, variant)) 58 .filter_map(|variant| build_pat(ctx.db, module, variant))
59 .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat)) 59 .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat))
60 .map(|pat| make::match_arm(iter::once(pat), make::expr_unit())) 60 .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
61 .collect() 61 .collect()
62 } else if let Some(enum_defs) = resolve_tuple_of_enum_def(&ctx.sema, &expr) { 62 } else if let Some(enum_defs) = resolve_tuple_of_enum_def(&ctx.sema, &expr) {
63 // Partial fill not currently supported for tuple of enums. 63 // Partial fill not currently supported for tuple of enums.
@@ -86,7 +86,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx) -> Option<Assist> {
86 ast::Pat::from(make::tuple_pat(patterns)) 86 ast::Pat::from(make::tuple_pat(patterns))
87 }) 87 })
88 .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat)) 88 .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat))
89 .map(|pat| make::match_arm(iter::once(pat), make::expr_unit())) 89 .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block()))
90 .collect() 90 .collect()
91 } else { 91 } else {
92 return None; 92 return None;
@@ -192,8 +192,8 @@ mod tests {
192 fn main() { 192 fn main() {
193 match A::As<|> { 193 match A::As<|> {
194 A::As, 194 A::As,
195 A::Bs{x,y:Some(_)} => (), 195 A::Bs{x,y:Some(_)} => {}
196 A::Cs(_, Some(_)) => (), 196 A::Cs(_, Some(_)) => {}
197 } 197 }
198 } 198 }
199 "#, 199 "#,
@@ -227,8 +227,8 @@ mod tests {
227 } 227 }
228 fn main() { 228 fn main() {
229 match A::As<|> { 229 match A::As<|> {
230 A::Bs{x,y:Some(_)} => (), 230 A::Bs{x,y:Some(_)} => {}
231 A::Cs(_, Some(_)) => (), 231 A::Cs(_, Some(_)) => {}
232 } 232 }
233 } 233 }
234 "#, 234 "#,
@@ -240,9 +240,9 @@ mod tests {
240 } 240 }
241 fn main() { 241 fn main() {
242 match <|>A::As { 242 match <|>A::As {
243 A::Bs{x,y:Some(_)} => (), 243 A::Bs{x,y:Some(_)} => {}
244 A::Cs(_, Some(_)) => (), 244 A::Cs(_, Some(_)) => {}
245 A::As => (), 245 A::As => {}
246 } 246 }
247 } 247 }
248 "#, 248 "#,
@@ -261,7 +261,7 @@ mod tests {
261 } 261 }
262 fn main() { 262 fn main() {
263 match A::As<|> { 263 match A::As<|> {
264 A::Cs(_) | A::Bs => (), 264 A::Cs(_) | A::Bs => {}
265 } 265 }
266 } 266 }
267 "#, 267 "#,
@@ -273,8 +273,8 @@ mod tests {
273 } 273 }
274 fn main() { 274 fn main() {
275 match <|>A::As { 275 match <|>A::As {
276 A::Cs(_) | A::Bs => (), 276 A::Cs(_) | A::Bs => {}
277 A::As => (), 277 A::As => {}
278 } 278 }
279 } 279 }
280 "#, 280 "#,
@@ -299,8 +299,8 @@ mod tests {
299 } 299 }
300 fn main() { 300 fn main() {
301 match A::As<|> { 301 match A::As<|> {
302 A::Bs if 0 < 1 => (), 302 A::Bs if 0 < 1 => {}
303 A::Ds(_value) => (), 303 A::Ds(_value) => { let x = 1; }
304 A::Es(B::Xs) => (), 304 A::Es(B::Xs) => (),
305 } 305 }
306 } 306 }
@@ -319,11 +319,11 @@ mod tests {
319 } 319 }
320 fn main() { 320 fn main() {
321 match <|>A::As { 321 match <|>A::As {
322 A::Bs if 0 < 1 => (), 322 A::Bs if 0 < 1 => {}
323 A::Ds(_value) => (), 323 A::Ds(_value) => { let x = 1; }
324 A::Es(B::Xs) => (), 324 A::Es(B::Xs) => (),
325 A::As => (), 325 A::As => {}
326 A::Cs => (), 326 A::Cs => {}
327 } 327 }
328 } 328 }
329 "#, 329 "#,
@@ -360,11 +360,11 @@ mod tests {
360 fn main() { 360 fn main() {
361 let a = A::As; 361 let a = A::As;
362 match <|>a { 362 match <|>a {
363 A::As => (), 363 A::As => {}
364 A::Bs => (), 364 A::Bs => {}
365 A::Cs(_) => (), 365 A::Cs(_) => {}
366 A::Ds(_, _) => (), 366 A::Ds(_, _) => {}
367 A::Es { x, y } => (), 367 A::Es { x, y } => {}
368 } 368 }
369 } 369 }
370 "#, 370 "#,
@@ -405,10 +405,10 @@ mod tests {
405 let a = A::One; 405 let a = A::One;
406 let b = B::One; 406 let b = B::One;
407 match <|>(a, b) { 407 match <|>(a, b) {
408 (A::One, B::One) => (), 408 (A::One, B::One) => {}
409 (A::One, B::Two) => (), 409 (A::One, B::Two) => {}
410 (A::Two, B::One) => (), 410 (A::Two, B::One) => {}
411 (A::Two, B::Two) => (), 411 (A::Two, B::Two) => {}
412 } 412 }
413 } 413 }
414 "#, 414 "#,
@@ -449,10 +449,10 @@ mod tests {
449 let a = A::One; 449 let a = A::One;
450 let b = B::One; 450 let b = B::One;
451 match <|>(&a, &b) { 451 match <|>(&a, &b) {
452 (A::One, B::One) => (), 452 (A::One, B::One) => {}
453 (A::One, B::Two) => (), 453 (A::One, B::Two) => {}
454 (A::Two, B::One) => (), 454 (A::Two, B::One) => {}
455 (A::Two, B::Two) => (), 455 (A::Two, B::Two) => {}
456 } 456 }
457 } 457 }
458 "#, 458 "#,
@@ -477,7 +477,7 @@ mod tests {
477 let a = A::One; 477 let a = A::One;
478 let b = B::One; 478 let b = B::One;
479 match (a<|>, b) { 479 match (a<|>, b) {
480 (A::Two, B::One) => (), 480 (A::Two, B::One) => {}
481 } 481 }
482 } 482 }
483 "#, 483 "#,
@@ -502,10 +502,10 @@ mod tests {
502 let a = A::One; 502 let a = A::One;
503 let b = B::One; 503 let b = B::One;
504 match (a<|>, b) { 504 match (a<|>, b) {
505 (A::Two, B::One) => (), 505 (A::Two, B::One) => {}
506 (A::One, B::One) => (), 506 (A::One, B::One) => {}
507 (A::One, B::Two) => (), 507 (A::One, B::Two) => {}
508 (A::Two, B::Two) => (), 508 (A::Two, B::Two) => {}
509 } 509 }
510 } 510 }
511 "#, 511 "#,
@@ -555,7 +555,7 @@ mod tests {
555 555
556 fn foo(a: &A) { 556 fn foo(a: &A) {
557 match <|>a { 557 match <|>a {
558 A::As => (), 558 A::As => {}
559 } 559 }
560 } 560 }
561 "#, 561 "#,
@@ -580,7 +580,7 @@ mod tests {
580 580
581 fn foo(a: &mut A) { 581 fn foo(a: &mut A) {
582 match <|>a { 582 match <|>a {
583 A::Es { x, y } => (), 583 A::Es { x, y } => {}
584 } 584 }
585 } 585 }
586 "#, 586 "#,
@@ -611,7 +611,7 @@ mod tests {
611 611
612 fn main() { 612 fn main() {
613 match E::X { 613 match E::X {
614 <|>_ => {}, 614 <|>_ => {}
615 } 615 }
616 } 616 }
617 "#, 617 "#,
@@ -620,8 +620,8 @@ mod tests {
620 620
621 fn main() { 621 fn main() {
622 match <|>E::X { 622 match <|>E::X {
623 E::X => (), 623 E::X => {}
624 E::Y => (), 624 E::Y => {}
625 } 625 }
626 } 626 }
627 "#, 627 "#,
@@ -648,8 +648,8 @@ mod tests {
648 648
649 fn main() { 649 fn main() {
650 match <|>X { 650 match <|>X {
651 X => (), 651 X => {}
652 foo::E::Y => (), 652 foo::E::Y => {}
653 } 653 }
654 } 654 }
655 "#, 655 "#,
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 9257ccd1a..1145b69e8 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -87,6 +87,9 @@ pub fn block_from_expr(e: ast::Expr) -> ast::Block {
87pub fn expr_unit() -> ast::Expr { 87pub fn expr_unit() -> ast::Expr {
88 expr_from_text("()") 88 expr_from_text("()")
89} 89}
90pub fn expr_empty_block() -> ast::Expr {
91 expr_from_text("{}")
92}
90pub fn expr_unimplemented() -> ast::Expr { 93pub fn expr_unimplemented() -> ast::Expr {
91 expr_from_text("unimplemented!()") 94 expr_from_text("unimplemented!()")
92} 95}