aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-18 19:51:47 +0000
committerAleksey Kladov <[email protected]>2020-03-18 19:51:47 +0000
commit0bf903411c6bf94a235383b2d60988ceee58ea90 (patch)
tree26fa8907363441be33736e891dded863a433f898 /crates/ra_assists/src/handlers
parentb28d41186698a6e2aa3d679ee63dd48304ca4262 (diff)
Use match_ast
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/move_bounds.rs23
1 files changed, 13 insertions, 10 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| {