mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
minor: Migrate remove_unnecessary_wrapper
to SyntaxEditor
This commit is contained in:
parent
59cd717602
commit
68b85ce66f
2 changed files with 63 additions and 20 deletions
|
@ -89,6 +89,10 @@ impl SyntaxFactory {
|
|||
ast
|
||||
}
|
||||
|
||||
pub fn expr_empty_block(&self) -> ast::BlockExpr {
|
||||
ast::BlockExpr { syntax: make::expr_empty_block().syntax().clone_for_update() }
|
||||
}
|
||||
|
||||
pub fn expr_bin(&self, lhs: ast::Expr, op: ast::BinaryOp, rhs: ast::Expr) -> ast::BinExpr {
|
||||
let ast::Expr::BinExpr(ast) =
|
||||
make::expr_bin_op(lhs.clone(), op, rhs.clone()).clone_for_update()
|
||||
|
@ -135,6 +139,22 @@ impl SyntaxFactory {
|
|||
ast.into()
|
||||
}
|
||||
|
||||
pub fn expr_return(&self, expr: Option<ast::Expr>) -> ast::ReturnExpr {
|
||||
let ast::Expr::ReturnExpr(ast) = make::expr_return(expr.clone()).clone_for_update() else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
if let Some(mut mapping) = self.mappings() {
|
||||
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
|
||||
if let Some(input) = expr {
|
||||
builder.map_node(input.syntax().clone(), ast.expr().unwrap().syntax().clone());
|
||||
}
|
||||
builder.finish(&mut mapping);
|
||||
}
|
||||
|
||||
ast
|
||||
}
|
||||
|
||||
pub fn let_stmt(
|
||||
&self,
|
||||
pattern: ast::Pat,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue