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 --- Cargo.lock | 4 ++-- 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 +- crates/completion/src/context.rs | 2 +- crates/hir/src/code_model.rs | 7 ++++--- crates/hir_def/src/body/lower.rs | 2 +- crates/hir_ty/src/display.rs | 2 +- crates/syntax/src/ast/generated/nodes.rs | 2 +- crates/syntax/src/lib.rs | 2 +- xtask/Cargo.toml | 2 +- 18 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f87c590a4..fe45f9dec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1804,9 +1804,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "ungrammar" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bffada52edc8f2a56160b286ea4640acf90ffcb21bded361ccb8ed43a1457" +checksum = "f96cc1b6938f7c548fbcc630bac5c896ae77a130909829ab18b8eab78c51b7ee" [[package]] name = "unicase" 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; } diff --git a/crates/completion/src/context.rs b/crates/completion/src/context.rs index 41de324d8..f979697ab 100644 --- a/crates/completion/src/context.rs +++ b/crates/completion/src/context.rs @@ -458,7 +458,7 @@ impl<'a> CompletionContext<'a> { } if let Some(block) = ast::BlockExpr::cast(node) { return Some( - block.expr().map(|e| e.syntax().text_range()) + block.tail_expr().map(|e| e.syntax().text_range()) == Some(name_ref.syntax().text_range()), ); } diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 1a4aa78fb..cc1938333 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1642,9 +1642,10 @@ impl Type { } pub fn is_fn(&self) -> bool { - matches!(&self.ty.value, - Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. }) | - Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. }) + matches!( + &self.ty.value, + Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. }) + | Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. }) ) } diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 17c72779b..6be1eaade 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -695,7 +695,7 @@ impl ExprCollector<'_> { self.collect_stmts_items(block.statements()); let statements = block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect(); - let tail = block.expr().map(|e| self.collect_expr(e)); + let tail = block.tail_expr().map(|e| self.collect_expr(e)); self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr) } diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index a54225c18..e9e949c47 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -168,7 +168,7 @@ pub enum DisplayTarget { impl DisplayTarget { fn is_source_code(&self) -> bool { - matches!(self, Self::SourceCode {..}) + matches!(self, Self::SourceCode { .. }) } fn is_test(&self) -> bool { matches!(self, Self::Test) diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index c5b80bffe..92ed2ee9d 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -484,7 +484,7 @@ impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } + pub fn tail_expr(&self) -> Option { support::child(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index da151e328..ea7482bb1 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -290,7 +290,7 @@ fn api_walkthrough() { // Let's get the `1 + 1` expression! let body: ast::BlockExpr = func.body().unwrap(); - let expr: ast::Expr = body.expr().unwrap(); + let expr: ast::Expr = body.tail_expr().unwrap(); // Enums are used to group related ast nodes together, and can be used for // matching. However, because there are no public fields, it's possible to diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 96b4ea448..7a2937f0e 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -15,7 +15,7 @@ flate2 = "1.0" pico-args = "0.3.1" proc-macro2 = "1.0.8" quote = "1.0.2" -ungrammar = "1.5" +ungrammar = "1.6" walkdir = "2.3.1" write-json = "0.1.0" xshell = "0.1" -- cgit v1.2.3