diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index dbf8e6370..0c908573d 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | //! This module contains free-standing functions for creating AST fragments out | 1 | //! This module contains free-standing functions for creating AST fragments out |
2 | //! of smaller pieces. | 2 | //! of smaller pieces. |
3 | use itertools::Itertools; | 3 | use itertools::Itertools; |
4 | use stdx::format_to; | ||
4 | 5 | ||
5 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; | 6 | use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; |
6 | 7 | ||
@@ -34,14 +35,14 @@ pub fn use_tree( | |||
34 | let mut buf = "use ".to_string(); | 35 | let mut buf = "use ".to_string(); |
35 | buf += &path.syntax().to_string(); | 36 | buf += &path.syntax().to_string(); |
36 | if let Some(use_tree_list) = use_tree_list { | 37 | if let Some(use_tree_list) = use_tree_list { |
37 | buf += &format!("::{}", use_tree_list); | 38 | format_to!(buf, "::{}", use_tree_list); |
38 | } | 39 | } |
39 | if add_star { | 40 | if add_star { |
40 | buf += "::*"; | 41 | buf += "::*"; |
41 | } | 42 | } |
42 | 43 | ||
43 | if let Some(alias) = alias { | 44 | if let Some(alias) = alias { |
44 | buf += &format!(" {}", alias); | 45 | format_to!(buf, " {}", alias); |
45 | } | 46 | } |
46 | ast_from_text(&buf) | 47 | ast_from_text(&buf) |
47 | } | 48 | } |
@@ -70,15 +71,15 @@ pub fn block_expr( | |||
70 | stmts: impl IntoIterator<Item = ast::Stmt>, | 71 | stmts: impl IntoIterator<Item = ast::Stmt>, |
71 | tail_expr: Option<ast::Expr>, | 72 | tail_expr: Option<ast::Expr>, |
72 | ) -> ast::BlockExpr { | 73 | ) -> ast::BlockExpr { |
73 | let mut text = "{\n".to_string(); | 74 | let mut buf = "{\n".to_string(); |
74 | for stmt in stmts.into_iter() { | 75 | for stmt in stmts.into_iter() { |
75 | text += &format!(" {}\n", stmt); | 76 | format_to!(buf, " {}\n", stmt); |
76 | } | 77 | } |
77 | if let Some(tail_expr) = tail_expr { | 78 | if let Some(tail_expr) = tail_expr { |
78 | text += &format!(" {}\n", tail_expr) | 79 | format_to!(buf, " {}\n", tail_expr) |
79 | } | 80 | } |
80 | text += "}"; | 81 | buf += "}"; |
81 | ast_from_text(&format!("fn f() {}", text)) | 82 | ast_from_text(&format!("fn f() {}", buf)) |
82 | } | 83 | } |
83 | 84 | ||
84 | pub fn block_from_expr(e: ast::Expr) -> ast::Block { | 85 | pub fn block_from_expr(e: ast::Expr) -> ast::Block { |