Skip to content

Commit 5faf07d

Browse files
bors[bot]matklad
andauthored
Merge #10429
10429: internal: remove deprecated method r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 745fd99 + 7dbf24f commit 5faf07d

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

crates/ide_assists/src/handlers/replace_if_let_with_match.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ pub(crate) fn replace_match_with_if_let(acc: &mut Assists, ctx: &AssistContext)
210210
ast::Expr::BlockExpr(block) => block,
211211
expr => make::block_expr(iter::empty(), Some(expr)),
212212
};
213-
let else_expr = match else_expr {
214-
ast::Expr::BlockExpr(block) if block.is_empty() => None,
215-
ast::Expr::TupleExpr(tuple) if tuple.fields().next().is_none() => None,
216-
expr => Some(expr),
217-
};
213+
let else_expr = if is_empty_expr(&else_expr) { None } else { Some(else_expr) };
218214
let if_let_expr = make::expr_if(
219215
condition,
220216
then_block,
@@ -257,7 +253,10 @@ fn pick_pattern_and_expr_order(
257253

258254
fn is_empty_expr(expr: &ast::Expr) -> bool {
259255
match expr {
260-
ast::Expr::BlockExpr(expr) => expr.is_empty(),
256+
ast::Expr::BlockExpr(expr) => match expr.stmt_list() {
257+
Some(it) => it.statements().next().is_none() && it.tail_expr().is_none(),
258+
None => true,
259+
},
261260
ast::Expr::TupleExpr(expr) => expr.fields().next().is_none(),
262261
_ => false,
263262
}

crates/syntax/src/ast/node_ext.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use parser::SyntaxKind;
1010
use rowan::{GreenNodeData, GreenTokenData};
1111

1212
use crate::{
13-
ast::{
14-
self, support, AstNode, AstToken, HasAttrs, HasGenericParams, HasModuleItem, HasName,
15-
SyntaxNode,
16-
},
13+
ast::{self, support, AstNode, AstToken, HasAttrs, HasGenericParams, HasName, SyntaxNode},
1714
NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
1815
};
1916

@@ -54,13 +51,6 @@ impl ast::HasModuleItem for ast::StmtList {}
5451

5552
impl ast::BlockExpr {
5653
// FIXME: remove all these methods, they belong to ast::StmtList
57-
pub fn items(&self) -> impl Iterator<Item = ast::Item> {
58-
self.stmt_list().into_iter().flat_map(|it| it.items())
59-
}
60-
61-
pub fn is_empty(&self) -> bool {
62-
self.statements().next().is_none() && self.tail_expr().is_none()
63-
}
6454
pub fn statements(&self) -> impl Iterator<Item = ast::Stmt> {
6555
self.stmt_list().into_iter().flat_map(|it| it.statements())
6656
}

0 commit comments

Comments
 (0)