Skip to content

Commit 0eed197

Browse files
committed
minor: Add expr_bin constructor to SyntaxFactory
1 parent 8877598 commit 0eed197

File tree

1 file changed

+17
-0
lines changed
  • src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory

1 file changed

+17
-0
lines changed

src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ impl SyntaxFactory {
8080
ast
8181
}
8282

83+
pub fn expr_bin(&self, lhs: ast::Expr, op: ast::BinaryOp, rhs: ast::Expr) -> ast::BinExpr {
84+
let ast::Expr::BinExpr(ast) =
85+
make::expr_bin_op(lhs.clone(), op, rhs.clone()).clone_for_update()
86+
else {
87+
unreachable!()
88+
};
89+
90+
if let Some(mut mapping) = self.mappings() {
91+
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
92+
builder.map_node(lhs.syntax().clone(), ast.lhs().unwrap().syntax().clone());
93+
builder.map_node(rhs.syntax().clone(), ast.rhs().unwrap().syntax().clone());
94+
builder.finish(&mut mapping);
95+
}
96+
97+
ast
98+
}
99+
83100
pub fn expr_path(&self, path: ast::Path) -> ast::Expr {
84101
let ast::Expr::PathExpr(ast) = make::expr_path(path.clone()).clone_for_update() else {
85102
unreachable!()

0 commit comments

Comments
 (0)