From 4d17658940ec73554dfef799b22e8829ab5ad61a Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 14:39:05 -0400 Subject: Use match_ast! in FnCallNode::with_node --- crates/ra_ide_api/src/call_info.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index e494f5620..3572825b5 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -4,7 +4,7 @@ use ra_db::SourceDatabase; use ra_syntax::{ algo::ancestors_at_offset, ast::{self, ArgListOwner}, - AstNode, SyntaxNode, TextUnit, + match_ast, AstNode, SyntaxNode, TextUnit, }; use test_utils::tested_by; @@ -91,14 +91,13 @@ enum FnCallNode { impl FnCallNode { fn with_node(syntax: &SyntaxNode, offset: TextUnit) -> Option { ancestors_at_offset(syntax, offset).find_map(|node| { - if let Some(expr) = ast::CallExpr::cast(node.clone()) { - Some(FnCallNode::CallExpr(expr)) - } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { - Some(FnCallNode::MethodCallExpr(expr)) - } else if let Some(expr) = ast::MacroCall::cast(node) { - Some(FnCallNode::MacroCallExpr(expr)) - } else { - None + match_ast! { + match node { + ast::CallExpr(it) => { Some(FnCallNode::CallExpr(it)) }, + ast::MethodCallExpr(it) => { Some(FnCallNode::MethodCallExpr(it)) }, + ast::MacroCall(it) => { Some(FnCallNode::MacroCallExpr(it)) }, + _ => { None }, + } } }) } -- cgit v1.2.3