aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--crates/assists/src/handlers/early_return.rs2
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs12
-rw-r--r--crates/assists/src/handlers/extract_variable.rs2
-rw-r--r--crates/assists/src/handlers/infer_function_return_type.rs4
-rw-r--r--crates/assists/src/handlers/inline_function.rs2
-rw-r--r--crates/assists/src/handlers/move_guard.rs4
-rw-r--r--crates/assists/src/handlers/pull_assignment_up.rs2
-rw-r--r--crates/assists/src/handlers/replace_if_let_with_match.rs2
-rw-r--r--crates/assists/src/handlers/wrap_return_type_in_result.rs8
-rw-r--r--crates/assists/src/utils.rs2
-rw-r--r--crates/completion/src/context.rs2
-rw-r--r--crates/hir/src/code_model.rs7
-rw-r--r--crates/hir_def/src/body/lower.rs2
-rw-r--r--crates/hir_ty/src/display.rs2
-rw-r--r--crates/syntax/src/ast/generated/nodes.rs2
-rw-r--r--crates/syntax/src/lib.rs2
-rw-r--r--xtask/Cargo.toml2
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"
1804 1804
1805[[package]] 1805[[package]]
1806name = "ungrammar" 1806name = "ungrammar"
1807version = "1.5.0" 1807version = "1.6.0"
1808source = "registry+https://github.com/rust-lang/crates.io-index" 1808source = "registry+https://github.com/rust-lang/crates.io-index"
1809checksum = "c11bffada52edc8f2a56160b286ea4640acf90ffcb21bded361ccb8ed43a1457" 1809checksum = "f96cc1b6938f7c548fbcc630bac5c896ae77a130909829ab18b8eab78c51b7ee"
1810 1810
1811[[package]] 1811[[package]]
1812name = "unicase" 1812name = "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)
69 69
70 let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?; 70 let parent_block = if_expr.syntax().parent()?.ancestors().find_map(ast::BlockExpr::cast)?;
71 71
72 if parent_block.expr()? != if_expr.clone().into() { 72 if parent_block.tail_expr()? != if_expr.clone().into() {
73 return None; 73 return None;
74 } 74 }
75 75
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
117 .into_iter() 117 .into_iter()
118 .filter(|(_, def)| match def { 118 .filter(|(_, def)| match def {
119 // only check type-namespace 119 // only check type-namespace
120 hir::ScopeDef::ModuleDef(def) => matches!(def, 120 hir::ScopeDef::ModuleDef(def) => matches!(
121 ModuleDef::Module(_) | ModuleDef::Adt(_) | 121 def,
122 ModuleDef::Variant(_) | ModuleDef::Trait(_) | 122 ModuleDef::Module(_)
123 ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_) 123 | ModuleDef::Adt(_)
124 | ModuleDef::Variant(_)
125 | ModuleDef::Trait(_)
126 | ModuleDef::TypeAlias(_)
127 | ModuleDef::BuiltinType(_)
124 ), 128 ),
125 _ => false, 129 _ => false,
126 }) 130 })
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 {
139 fn from(to_extract: &ast::Expr) -> Option<Anchor> { 139 fn from(to_extract: &ast::Expr) -> Option<Anchor> {
140 to_extract.syntax().ancestors().find_map(|node| { 140 to_extract.syntax().ancestors().find_map(|node| {
141 if let Some(expr) = 141 if let Some(expr) =
142 node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr()) 142 node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.tail_expr())
143 { 143 {
144 if expr.syntax() == &node { 144 if expr.syntax() == &node {
145 mark::hit!(test_extract_var_last_expr); 145 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
89 let body = closure.body()?; 89 let body = closure.body()?;
90 let body_start = body.syntax().first_token()?.text_range().start(); 90 let body_start = body.syntax().first_token()?.text_range().start();
91 let (tail_expr, wrap_expr) = match body { 91 let (tail_expr, wrap_expr) = match body {
92 ast::Expr::BlockExpr(block) => (block.expr()?, false), 92 ast::Expr::BlockExpr(block) => (block.tail_expr()?, false),
93 body => (body, true), 93 body => (body, true),
94 }; 94 };
95 95
@@ -101,7 +101,7 @@ fn extract_tail(ctx: &AssistContext) -> Option<(FnType, ast::Expr, InsertOrRepla
101 let action = ret_ty_to_action(func.ret_type(), rparen_pos)?; 101 let action = ret_ty_to_action(func.ret_type(), rparen_pos)?;
102 102
103 let body = func.body()?; 103 let body = func.body()?;
104 let tail_expr = body.expr()?; 104 let tail_expr = body.tail_expr()?;
105 105
106 let ret_range_end = body.l_curly_token()?.text_range().start(); 106 let ret_range_end = body.l_curly_token()?.text_range().start();
107 let ret_range = TextRange::new(rparen_pos, ret_range_end); 107 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<
71 statements.extend(body.statements()); 71 statements.extend(body.statements());
72 72
73 let original_indentation = call.indent_level(); 73 let original_indentation = call.indent_level();
74 let replacement = make::block_expr(statements, body.expr()) 74 let replacement = make::block_expr(statements, body.tail_expr())
75 .reset_indent() 75 .reset_indent()
76 .indent(original_indentation); 76 .indent(original_indentation);
77 77
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
98 let mut replace_node = None; 98 let mut replace_node = None;
99 let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| { 99 let if_expr: IfExpr = IfExpr::cast(arm_body.syntax().clone()).or_else(|| {
100 let block_expr = BlockExpr::cast(arm_body.syntax().clone())?; 100 let block_expr = BlockExpr::cast(arm_body.syntax().clone())?;
101 if let Expr::IfExpr(e) = block_expr.expr()? { 101 if let Expr::IfExpr(e) = block_expr.tail_expr()? {
102 replace_node = Some(block_expr.syntax().clone()); 102 replace_node = Some(block_expr.syntax().clone());
103 Some(e) 103 Some(e)
104 } else { 104 } else {
@@ -128,7 +128,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
128 |edit| { 128 |edit| {
129 let then_only_expr = then_block.statements().next().is_none(); 129 let then_only_expr = then_block.statements().next().is_none();
130 130
131 match &then_block.expr() { 131 match &then_block.tail_expr() {
132 Some(then_expr) if then_only_expr => { 132 Some(then_expr) if then_only_expr => {
133 edit.replace(replace_node.text_range(), then_expr.syntax().text()) 133 edit.replace(replace_node.text_range(), then_expr.syntax().text())
134 } 134 }
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(
118 sema: &hir::Semantics<ide_db::RootDatabase>, 118 sema: &hir::Semantics<ide_db::RootDatabase>,
119 name: &ast::Expr, 119 name: &ast::Expr,
120) -> Option<ast::BlockExpr> { 120) -> Option<ast::BlockExpr> {
121 if block.expr().is_some() { 121 if block.tail_expr().is_some() {
122 return None; 122 return None;
123 } 123 }
124 124
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)
138 }; 138 };
139 let else_expr = match else_expr { 139 let else_expr = match else_expr {
140 ast::Expr::BlockExpr(block) 140 ast::Expr::BlockExpr(block)
141 if block.statements().count() == 0 && block.expr().is_none() => 141 if block.statements().count() == 0 && block.tail_expr().is_none() =>
142 { 142 {
143 None 143 None
144 } 144 }
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 {
98 } 98 }
99 99
100 // Browse tail expressions for each block 100 // Browse tail expressions for each block
101 if let Some(expr) = block_expr.expr() { 101 if let Some(expr) = block_expr.tail_expr() {
102 if let Some(last_exprs) = get_tail_expr_from_block(&expr) { 102 if let Some(last_exprs) = get_tail_expr_from_block(&expr) {
103 for last_expr in last_exprs { 103 for last_expr in last_exprs {
104 let last_expr = match last_expr { 104 let last_expr = match last_expr {
@@ -170,7 +170,7 @@ impl TailReturnCollector {
170 } 170 }
171 171
172 fn collect_tail_exprs(&mut self, block: &BlockExpr) { 172 fn collect_tail_exprs(&mut self, block: &BlockExpr) {
173 if let Some(expr) = block.expr() { 173 if let Some(expr) = block.tail_expr() {
174 self.handle_exprs(&expr, true); 174 self.handle_exprs(&expr, true);
175 self.fetch_tail_exprs(&expr); 175 self.fetch_tail_exprs(&expr);
176 } 176 }
@@ -206,7 +206,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
206 Expr::IfExpr(if_expr) => { 206 Expr::IfExpr(if_expr) => {
207 let mut nodes = vec![]; 207 let mut nodes = vec![];
208 for block in if_expr.blocks() { 208 for block in if_expr.blocks() {
209 if let Some(block_expr) = block.expr() { 209 if let Some(block_expr) = block.tail_expr() {
210 if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) { 210 if let Some(tail_exprs) = get_tail_expr_from_block(&block_expr) {
211 nodes.extend(tail_exprs); 211 nodes.extend(tail_exprs);
212 } 212 }
@@ -228,7 +228,7 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
228 while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)]) 228 while_expr.syntax().last_child().map(|lc| vec![NodeType::Node(lc)])
229 } 229 }
230 Expr::BlockExpr(block_expr) => { 230 Expr::BlockExpr(block_expr) => {
231 block_expr.expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())]) 231 block_expr.tail_expr().map(|lc| vec![NodeType::Node(lc.syntax().clone())])
232 } 232 }
233 Expr::MatchExpr(match_expr) => { 233 Expr::MatchExpr(match_expr) => {
234 let arm_list = match_expr.match_arm_list()?; 234 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<ast::Expr> {
37 non_trivial_children.next().is_some() 37 non_trivial_children.next().is_some()
38 }; 38 };
39 39
40 if let Some(expr) = block.expr() { 40 if let Some(expr) = block.tail_expr() {
41 if has_anything_else(expr.syntax()) { 41 if has_anything_else(expr.syntax()) {
42 return None; 42 return None;
43 } 43 }
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> {
458 } 458 }
459 if let Some(block) = ast::BlockExpr::cast(node) { 459 if let Some(block) = ast::BlockExpr::cast(node) {
460 return Some( 460 return Some(
461 block.expr().map(|e| e.syntax().text_range()) 461 block.tail_expr().map(|e| e.syntax().text_range())
462 == Some(name_ref.syntax().text_range()), 462 == Some(name_ref.syntax().text_range()),
463 ); 463 );
464 } 464 }
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 {
1642 } 1642 }
1643 1643
1644 pub fn is_fn(&self) -> bool { 1644 pub fn is_fn(&self) -> bool {
1645 matches!(&self.ty.value, 1645 matches!(
1646 Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. }) | 1646 &self.ty.value,
1647 Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. }) 1647 Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(..), .. })
1648 | Ty::Apply(ApplicationTy { ctor: TypeCtor::FnPtr { .. }, .. })
1648 ) 1649 )
1649 } 1650 }
1650 1651
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<'_> {
695 self.collect_stmts_items(block.statements()); 695 self.collect_stmts_items(block.statements());
696 let statements = 696 let statements =
697 block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect(); 697 block.statements().filter_map(|s| self.collect_stmt(s)).flatten().collect();
698 let tail = block.expr().map(|e| self.collect_expr(e)); 698 let tail = block.tail_expr().map(|e| self.collect_expr(e));
699 self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr) 699 self.alloc_expr(Expr::Block { statements, tail, label: None }, syntax_node_ptr)
700 } 700 }
701 701
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 {
168 168
169impl DisplayTarget { 169impl DisplayTarget {
170 fn is_source_code(&self) -> bool { 170 fn is_source_code(&self) -> bool {
171 matches!(self, Self::SourceCode {..}) 171 matches!(self, Self::SourceCode { .. })
172 } 172 }
173 fn is_test(&self) -> bool { 173 fn is_test(&self) -> bool {
174 matches!(self, Self::Test) 174 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 {}
484impl BlockExpr { 484impl BlockExpr {
485 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 485 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
486 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 486 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
487 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 487 pub fn tail_expr(&self) -> Option<Expr> { support::child(&self.syntax) }
488 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 488 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
489} 489}
490#[derive(Debug, Clone, PartialEq, Eq, Hash)] 490#[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() {
290 290
291 // Let's get the `1 + 1` expression! 291 // Let's get the `1 + 1` expression!
292 let body: ast::BlockExpr = func.body().unwrap(); 292 let body: ast::BlockExpr = func.body().unwrap();
293 let expr: ast::Expr = body.expr().unwrap(); 293 let expr: ast::Expr = body.tail_expr().unwrap();
294 294
295 // Enums are used to group related ast nodes together, and can be used for 295 // Enums are used to group related ast nodes together, and can be used for
296 // matching. However, because there are no public fields, it's possible to 296 // 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"
15pico-args = "0.3.1" 15pico-args = "0.3.1"
16proc-macro2 = "1.0.8" 16proc-macro2 = "1.0.8"
17quote = "1.0.2" 17quote = "1.0.2"
18ungrammar = "1.5" 18ungrammar = "1.6"
19walkdir = "2.3.1" 19walkdir = "2.3.1"
20write-json = "0.1.0" 20write-json = "0.1.0"
21xshell = "0.1" 21xshell = "0.1"