From 0bf903411c6bf94a235383b2d60988ceee58ea90 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Wed, 18 Mar 2020 20:51:47 +0100
Subject: [PATCH] Use match_ast

---
 crates/ra_assists/src/handlers/move_bounds.rs | 23 +++++++++++--------
 crates/ra_syntax/src/lib.rs                   |  4 ++--
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs
index 342a770ec22..93f26f51ae0 100644
--- a/crates/ra_assists/src/handlers/move_bounds.rs
+++ b/crates/ra_assists/src/handlers/move_bounds.rs
@@ -1,6 +1,6 @@
 use ra_syntax::{
     ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
-    SyntaxElement,
+    match_ast,
     SyntaxKind::*,
 };
 
@@ -34,15 +34,18 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
         return None;
     }
 
-    let anchor: SyntaxElement = match parent.kind() {
-        FN_DEF => ast::FnDef::cast(parent)?.body()?.syntax().clone().into(),
-        TRAIT_DEF => ast::TraitDef::cast(parent)?.item_list()?.syntax().clone().into(),
-        IMPL_DEF => ast::ImplDef::cast(parent)?.item_list()?.syntax().clone().into(),
-        ENUM_DEF => ast::EnumDef::cast(parent)?.variant_list()?.syntax().clone().into(),
-        STRUCT_DEF => parent
-            .children_with_tokens()
-            .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?,
-        _ => return None,
+    let anchor = match_ast! {
+        match parent {
+            ast::FnDef(it) => it.body()?.syntax().clone().into(),
+            ast::TraitDef(it) => it.item_list()?.syntax().clone().into(),
+            ast::ImplDef(it) => it.item_list()?.syntax().clone().into(),
+            ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(),
+            ast::StructDef(it) => {
+                it.syntax().children_with_tokens()
+                    .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?
+            },
+            _ => return None
+        }
     };
 
     ctx.add_assist(AssistId("move_bounds_to_where_clause"), "Move to where clause", |edit| {
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index e3f74da6dea..cef926ed3b3 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -179,10 +179,10 @@ macro_rules! match_ast {
     (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
 
     (match ($node:expr) {
-        $( ast::$ast:ident($it:ident) => $res:block, )*
+        $( ast::$ast:ident($it:ident) => $res:expr, )*
         _ => $catch_all:expr $(,)?
     }) => {{
-        $( if let Some($it) = ast::$ast::cast($node.clone()) $res else )*
+        $( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*
         { $catch_all }
     }};
 }