diff --git a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs index 8d11e0bac94..9dc1da2461a 100644 --- a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs +++ b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs @@ -52,10 +52,7 @@ pub(crate) fn convert_named_struct_to_tuple_struct( acc: &mut Assists, ctx: &AssistContext<'_>, ) -> Option<()> { - let strukt = ctx - .find_node_at_offset::() - .map(Either::Left) - .or_else(|| ctx.find_node_at_offset::().map(Either::Right))?; + let strukt = ctx.find_node_at_offset::>()?; let field_list = strukt.as_ref().either(|s| s.field_list(), |v| v.field_list())?; let record_fields = match field_list { ast::FieldList::RecordFieldList(it) => it, diff --git a/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs index b0383291e73..772e032fb29 100644 --- a/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -50,10 +50,7 @@ pub(crate) fn convert_tuple_struct_to_named_struct( acc: &mut Assists, ctx: &AssistContext<'_>, ) -> Option<()> { - let strukt = ctx - .find_node_at_offset::() - .map(Either::Left) - .or_else(|| ctx.find_node_at_offset::().map(Either::Right))?; + let strukt = ctx.find_node_at_offset::>()?; let field_list = strukt.as_ref().either(|s| s.field_list(), |v| v.field_list())?; let tuple_fields = match field_list { ast::FieldList::TupleFieldList(it) => it, diff --git a/crates/ide-assists/src/handlers/extract_type_alias.rs b/crates/ide-assists/src/handlers/extract_type_alias.rs index 6c0238f35d0..b310c2db9fa 100644 --- a/crates/ide-assists/src/handlers/extract_type_alias.rs +++ b/crates/ide-assists/src/handlers/extract_type_alias.rs @@ -1,9 +1,6 @@ use either::Either; use ide_db::syntax_helpers::node_ext::walk_ty; -use syntax::{ - ast::{self, edit::IndentLevel, make, AstNode, HasGenericParams, HasName}, - match_ast, -}; +use syntax::ast::{self, edit::IndentLevel, make, AstNode, HasGenericParams, HasName}; use crate::{AssistContext, AssistId, AssistKind, Assists}; @@ -31,15 +28,8 @@ pub(crate) fn extract_type_alias(acc: &mut Assists, ctx: &AssistContext<'_>) -> let ty = ctx.find_node_at_range::()?; let item = ty.syntax().ancestors().find_map(ast::Item::cast)?; - let assoc_owner = item.syntax().ancestors().nth(2).and_then(|it| { - match_ast! { - match it { - ast::Trait(tr) => Some(Either::Left(tr)), - ast::Impl(impl_) => Some(Either::Right(impl_)), - _ => None, - } - } - }); + let assoc_owner = + item.syntax().ancestors().nth(2).and_then(Either::::cast); let node = assoc_owner.as_ref().map_or_else( || item.syntax(), |impl_| impl_.as_ref().either(AstNode::syntax, AstNode::syntax), diff --git a/crates/ide-assists/src/handlers/reorder_fields.rs b/crates/ide-assists/src/handlers/reorder_fields.rs index a899c7a6457..58dcaf9a221 100644 --- a/crates/ide-assists/src/handlers/reorder_fields.rs +++ b/crates/ide-assists/src/handlers/reorder_fields.rs @@ -20,10 +20,7 @@ // const test: Foo = Foo {foo: 1, bar: 0} // ``` pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { - let record = ctx - .find_node_at_offset::() - .map(Either::Left) - .or_else(|| ctx.find_node_at_offset::().map(Either::Right))?; + let record = ctx.find_node_at_offset::>()?; let path = record.as_ref().either(|it| it.path(), |it| it.path())?; let ranks = compute_fields_ranks(&path, ctx)?; diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index b214fa12a4f..f0c6505ee6e 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -230,15 +230,8 @@ fn hover_ranged( config: &HoverConfig, ) -> Option> { // FIXME: make this work in attributes - let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| { - match_ast! { - match it { - ast::Expr(expr) => Some(Either::Left(expr)), - ast::Pat(pat) => Some(Either::Right(pat)), - _ => None, - } - } - })?; + let expr_or_pat = + file.covering_element(range).ancestors().find_map(Either::::cast)?; let res = match &expr_or_pat { Either::Left(ast::Expr::TryExpr(try_expr)) => render::try_expr(sema, config, try_expr), Either::Left(ast::Expr::PrefixExpr(prefix_expr))