diff options
| author | Laurențiu Nicola <lnicola@dend.ro> | 2022-11-09 21:49:10 +0200 |
|---|---|---|
| committer | Laurențiu Nicola <lnicola@dend.ro> | 2022-11-09 21:49:10 +0200 |
| commit | ff118a84cc7cfc3cc5048528de9a54cd752c7559 (patch) | |
| tree | c738a19d43aba307c37e23aa8695010ae7ae9ee5 /src/tools/rust-analyzer/crates/syntax | |
| parent | cc9b259b5e94e4543b96dca236e3a1af5ec496c9 (diff) | |
| parent | d03c1c87d4ca2d524646316387d47b12524ac451 (diff) | |
:arrow_up: rust-analyzer
Diffstat (limited to 'src/tools/rust-analyzer/crates/syntax')
| -rw-r--r-- | src/tools/rust-analyzer/crates/syntax/src/ast/make.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs index 4057a75e7c1..8c26009add2 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs @@ -334,6 +334,10 @@ pub fn block_expr( ast_from_text(&format!("fn f() {buf}")) } +pub fn tail_only_block_expr(tail_expr: ast::Expr) -> ast::BlockExpr { + ast_from_text(&format!("fn f() {{ {tail_expr} }}")) +} + /// Ideally this function wouldn't exist since it involves manual indenting. /// It differs from `make::block_expr` by also supporting comments. /// @@ -656,6 +660,22 @@ pub fn let_stmt( }; ast_from_text(&format!("fn f() {{ {text} }}")) } + +pub fn let_else_stmt( + pattern: ast::Pat, + ty: Option<ast::Type>, + expr: ast::Expr, + diverging: ast::BlockExpr, +) -> ast::LetStmt { + let mut text = String::new(); + format_to!(text, "let {pattern}"); + if let Some(ty) = ty { + format_to!(text, ": {ty}"); + } + format_to!(text, " = {expr} else {diverging};"); + ast_from_text(&format!("fn f() {{ {text} }}")) +} + pub fn expr_stmt(expr: ast::Expr) -> ast::ExprStmt { let semi = if expr.is_block_like() { "" } else { ";" }; ast_from_text(&format!("fn f() {{ {expr}{semi} (); }}")) |
