From f9707cde6801f13cc4c20e3e08cee07ef23b8563 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 5 Jan 2021 15:45:46 +0300 Subject: Rename expr -> tail_expr --- crates/assists/src/handlers/early_return.rs | 2 +- .../assists/src/handlers/extract_struct_from_enum_variant.rs | 12 ++++++++---- crates/assists/src/handlers/extract_variable.rs | 2 +- crates/assists/src/handlers/infer_function_return_type.rs | 4 ++-- crates/assists/src/handlers/inline_function.rs | 2 +- crates/assists/src/handlers/move_guard.rs | 4 ++-- crates/assists/src/handlers/pull_assignment_up.rs | 2 +- crates/assists/src/handlers/replace_if_let_with_match.rs | 2 +- crates/assists/src/handlers/wrap_return_type_in_result.rs | 8 ++++---- crates/assists/src/utils.rs | 2 +- 10 files changed, 22 insertions(+), 18 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/handlers/early_return.rs b/crates/assists/src/handlers/early_return.rs index 7bcc318a9..2c48f32bf 100644 --- a/crates/assists/src/handlers/early_return.rs +++ b/crates/assists/src/handlers/early_return.rs @@ -69,7 +69,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?; - if parent_block.expr()? != if_expr.clone().into() { + if parent_block.tail_expr()? != if_expr.clone().into() { return None; } diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 030b9cd0c..6f35a061c 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -117,10 +117,14 @@ fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &Va .into_iter() .filter(|(_, def)| match def { // only check type-namespace - hir::ScopeDef::ModuleDef(def) => matches!(def, - ModuleDef::Module(_) | ModuleDef::Adt(_) | - ModuleDef::Variant(_) | ModuleDef::Trait(_) | - ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_) + hir::ScopeDef::ModuleDef(def) => matches!( + def, + ModuleDef::Module(_) + | ModuleDef::Adt(_) + | ModuleDef::Variant(_) + | ModuleDef::Trait(_) + | ModuleDef::TypeAlias(_) + | ModuleDef::BuiltinType(_) ), _ => false, }) diff --git a/crates/assists/src/handlers/extract_variable.rs b/crates/assists/src/handlers/extract_variable.rs index 9957012fe..291809205 100644 --- a/crates/assists/src/handlers/extract_variable.rs +++ b/crates/assists/src/handlers/extract_variable.rs @@ -139,7 +139,7 @@ impl Anchor { fn from(to_extract: &ast::Expr) -> Option { to_extract.syntax().ancestors().find_map(|node| { if let Some(expr) = - node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr()) + node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.tail_expr()) { if expr.syntax() == &node { mark::hit!(test_extract_var_last_expr); diff --git a/crates/assists/src/handlers/infer_function_return_type.rs b/crates/assists/src/handlers/infer_function_return_type.rs index aa584eb03..f499cdfdc 100644 --- a/crates/assists/src/handlers/infer_function_return_type.rs +++ b/crates/assists/src/handlers/infer_function_return_type.rs @@ -89,7 +89,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla let body = closure.body()?; let body_start = body.syntax().first_token()?.text_range().start(); let (tail_expr, wrap_expr) = match body { - ast::Expr::BlockExpr(block) => (block.expr()?, false), + ast::Expr::BlockExpr(block) => (block.tail_expr()?, false), body => (body, true), }; @@ -101,7 +101,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla let action = ret_ty_to_action(func.ret_type(), rparen_pos)?; let body = func.body()?; - let tail_expr = body.expr()?; + let tail_expr = body.tail_expr()?; let ret_range_end = body.l_curly_token()?.text_range().start(); let ret_range = TextRange::new(rparen_pos, ret_range_end); diff --git a/crates/assists/src/handlers/inline_function.rs b/crates/assists/src/handlers/inline_function.rs index 2edf252b7..6e351bdcd 100644 --- a/crates/assists/src/handlers/inline_function.rs +++ b/crates/assists/src/handlers/inline_function.rs @@ -71,7 +71,7 @@ pub(crate) fn inline_function(acc: &mut Assists, ctx: &AssistContext) -> Option< statements.extend(body.statements()); let original_indentation = call.indent_level(); - let replacement = make::block_expr(statements, body.expr()) + let replacement = make::block_expr(statements, body.tail_expr()) .reset_indent() .indent(original_indentation); diff --git a/crates/assists/src/handlers/move_guard.rs b/crates/assists/src/handlers/move_guard.rs index eaffd80ce..4318ca6dc 100644 --- a/crates/assists/src/handlers/move_guard.rs +++ b/crates/assists/src/handlers/move_guard.rs @@ -98,7 +98,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex let mut replace_node = None; let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| { let block_expr = BlockExpr::cast(arm_body.syntax().clone())?; - if let Expr::IfExpr(e) = block_expr.expr()? { + if let Expr::IfExpr(e) = block_expr.tail_expr()? { replace_node = Some(block_expr.syntax().clone()); Some(e) } else { @@ -128,7 +128,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex |edit| { let then_only_expr = then_block.statements().next().is_none(); - match &then_block.expr() { + match &then_block.tail_expr() { Some(then_expr) if then_only_expr => { edit.replace(replace_node.text_range(), then_expr.syntax().text()) } diff --git a/crates/assists/src/handlers/pull_assignment_up.rs b/crates/assists/src/handlers/pull_assignment_up.rs index 560d93e10..63b662fad 100644 --- a/crates/assists/src/handlers/pull_assignment_up.rs +++ b/crates/assists/src/handlers/pull_assignment_up.rs @@ -118,7 +118,7 @@ fn exprify_block( sema: &hir::Semantics, name: &ast::Expr, ) -> Option { - if block.expr().is_some() { + if block.tail_expr().is_some() { return None; } diff --git a/crates/assists/src/handlers/replace_if_let_with_match.rs b/crates/assists/src/handlers/replace_if_let_with_match.rs index 4a355c66f..b67219222 100644 --- a/crates/assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/assists/src/handlers/replace_if_let_with_match.rs @@ -138,7 +138,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext) }; let else_expr = match else_expr { ast::Expr::BlockExpr(block) - if block.statements().count() == 0 && block.expr().is_none() => + if block.statements().count() == 0 && block.tail_expr().is_none() => { None } diff --git a/crates/assists/src/handlers/wrap_return_type_in_result.rs b/crates/assists/src/handlers/wrap_return_type_in_result.rs index 59e5debb1..358b61046 100644 --- a/crates/assists/src/handlers/wrap_return_type_in_result.rs +++ b/crates/assists/src/handlers/wrap_return_type_in_result.rs @@ -98,7 +98,7 @@ impl TailReturnCollector { } // Browse tail expressions for each block - if let Some(expr) = block_expr.expr() { + if let Some(expr) = block_expr.tail_expr() { if let Some(last_exprs) = get_tail_expr_from_block(&expr) { for last_expr in last_exprs { let last_expr = match last_expr { @@ -170,7 +170,7 @@ impl TailReturnCollector { } fn collect_tail_exprs(&mut self, block: &BlockExpr) { - if let Some(expr) = block.expr() { + if let Some(expr) = block.tail_expr() { self.handle_exprs(&expr, true); self.fetch_tail_exprs(&expr); } @@ -206,7 +206,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option> { Expr::IfExpr(if_expr) => { let mut nodes = vec![]; for block in if_expr.blocks() { - if let Some(block_expr) = block.expr() { + if let Some(block_expr) = block.tail_expr() { if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) { nodes.extend(tail_exprs); } @@ -228,7 +228,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option> { while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)]) } Expr::BlockExpr(block_expr) => { - block_expr.expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())]) + block_expr.tail_expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())]) } Expr::MatchExpr(match_expr) => { let arm_list = match_expr.match_arm_list()?; diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index b05596446..8212cd129 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -37,7 +37,7 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option { non_trivial_children.next().is_some() }; - if let Some(expr) = block.expr() { + if let Some(expr) = block.tail_expr() { if has_anything_else(expr.syntax()) { return None; } -- cgit v1.2.3