Skip to content

Commit b376cab

Browse files
bors[bot]matklad
andauthored
Merge #3643
3643: Use match_ast r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents b28d411 + 0bf9034 commit b376cab

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

crates/ra_assists/src/handlers/move_bounds.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ra_syntax::{
22
ast::{self, edit::AstNodeEdit, make, AstNode, NameOwner, TypeBoundsOwner},
3-
SyntaxElement,
3+
match_ast,
44
SyntaxKind::*,
55
};
66

@@ -34,15 +34,18 @@ pub(crate) fn move_bounds_to_where_clause(ctx: AssistCtx) -> Option<Assist> {
3434
return None;
3535
}
3636

37-
let anchor: SyntaxElement = match parent.kind() {
38-
FN_DEF => ast::FnDef::cast(parent)?.body()?.syntax().clone().into(),
39-
TRAIT_DEF => ast::TraitDef::cast(parent)?.item_list()?.syntax().clone().into(),
40-
IMPL_DEF => ast::ImplDef::cast(parent)?.item_list()?.syntax().clone().into(),
41-
ENUM_DEF => ast::EnumDef::cast(parent)?.variant_list()?.syntax().clone().into(),
42-
STRUCT_DEF => parent
43-
.children_with_tokens()
44-
.find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?,
45-
_ => return None,
37+
let anchor = match_ast! {
38+
match parent {
39+
ast::FnDef(it) => it.body()?.syntax().clone().into(),
40+
ast::TraitDef(it) => it.item_list()?.syntax().clone().into(),
41+
ast::ImplDef(it) => it.item_list()?.syntax().clone().into(),
42+
ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(),
43+
ast::StructDef(it) => {
44+
it.syntax().children_with_tokens()
45+
.find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)?
46+
},
47+
_ => return None
48+
}
4649
};
4750

4851
ctx.add_assist(AssistId("move_bounds_to_where_clause"), "Move to where clause", |edit| {

crates/ra_syntax/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ macro_rules! match_ast {
179179
(match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
180180

181181
(match ($node:expr) {
182-
$( ast::$ast:ident($it:ident) => $res:block, )*
182+
$( ast::$ast:ident($it:ident) => $res:expr, )*
183183
_ => $catch_all:expr $(,)?
184184
}) => {{
185-
$( if let Some($it) = ast::$ast::cast($node.clone()) $res else )*
185+
$( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )*
186186
{ $catch_all }
187187
}};
188188
}

0 commit comments

Comments
 (0)