aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/move_bounds.rs23
-rw-r--r--crates/ra_syntax/src/lib.rs4
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 342a770ec..93f26f51a 100644
--- a/crates/ra_assists/src/handlers/move_bounds.rs
+++ b/crates/ra_assists/src/handlers/move_bounds.rs
@@ -1,6 +1,6 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner}, 2 ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
3 SyntaxElement, 3 match_ast,
4 SyntaxKind::*, 4 SyntaxKind::*,
5}; 5};
6 6
@@ -34,15 +34,18 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
34 return None; 34 return None;
35 } 35 }
36 36
37 let anchor: SyntaxElement = match parent.kind() { 37 let anchor = match_ast! {
38 FN_DEF => ast::FnDef::cast(parent)?.body()?.syntax().clone().into(), 38 match parent {
39 TRAIT_DEF => ast::TraitDef::cast(parent)?.item_list()?.syntax().clone().into(), 39 ast::FnDef(it) => it.body()?.syntax().clone().into(),
40 IMPL_DEF => ast::ImplDef::cast(parent)?.item_list()?.syntax().clone().into(), 40 ast::TraitDef(it) => it.item_list()?.syntax().clone().into(),
41 ENUM_DEF => ast::EnumDef::cast(parent)?.variant_list()?.syntax().clone().into(), 41 ast::ImplDef(it) => it.item_list()?.syntax().clone().into(),
42 STRUCT_DEF => parent 42 ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(),
43 .children_with_tokens() 43 ast::StructDef(it) => {
44 .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?, 44 it.syntax().children_with_tokens()
45 _ => return None, 45 .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?
46 },
47 _ => return None
48 }
46 }; 49 };
47 50
48 ctx.add_assist(AssistId("move_bounds_to_where_clause"), "Move to where clause", |edit| { 51 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 e3f74da6d..cef926ed3 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -179,10 +179,10 @@ macro_rules! match_ast {
179 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) }; 179 (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
180 180
181 (match ($node:expr) { 181 (match ($node:expr) {
182 $( ast::$ast:ident($it:ident) => $res:block, )* 182 $( ast::$ast:ident($it:ident) => $res:expr, )*
183 _ => $catch_all:expr $(,)? 183 _ => $catch_all:expr $(,)?
184 }) => {{ 184 }) => {{
185 $( if let Some($it) = ast::$ast::cast($node.clone()) $res else )* 185 $( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*
186 { $catch_all } 186 { $catch_all }
187 }}; 187 }};
188} 188}