@@ -13,13 +13,13 @@ pub fn name_ref(text: &str) -> ast::NameRef {
13
13
}
14
14
15
15
pub fn path_segment ( name_ref : ast:: NameRef ) -> ast:: PathSegment {
16
- ast_from_text ( & format ! ( "use {};" , name_ref. syntax ( ) ) )
16
+ ast_from_text ( & format ! ( "use {};" , name_ref) )
17
17
}
18
18
pub fn path_unqualified ( segment : ast:: PathSegment ) -> ast:: Path {
19
- path_from_text ( & format ! ( "use {}" , segment. syntax ( ) ) )
19
+ path_from_text ( & format ! ( "use {}" , segment) )
20
20
}
21
21
pub fn path_qualified ( qual : ast:: Path , segment : ast:: PathSegment ) -> ast:: Path {
22
- path_from_text ( & format ! ( "{}::{}" , qual. syntax ( ) , segment. syntax ( ) ) )
22
+ path_from_text ( & format ! ( "{}::{}" , qual, segment) )
23
23
}
24
24
fn path_from_text ( text : & str ) -> ast:: Path {
25
25
ast_from_text ( text)
@@ -33,10 +33,10 @@ pub fn use_tree(
33
33
let mut buf = "use " . to_string ( ) ;
34
34
buf += & path. syntax ( ) . to_string ( ) ;
35
35
if let Some ( use_tree_list) = use_tree_list {
36
- buf += & format ! ( "::{}" , use_tree_list. syntax ( ) ) ;
36
+ buf += & format ! ( "::{}" , use_tree_list) ;
37
37
}
38
38
if let Some ( alias) = alias {
39
- buf += & format ! ( " {}" , alias. syntax ( ) ) ;
39
+ buf += & format ! ( " {}" , alias) ;
40
40
}
41
41
ast_from_text ( & buf)
42
42
}
@@ -47,13 +47,13 @@ pub fn use_tree_list(use_trees: impl IntoIterator<Item = ast::UseTree>) -> ast::
47
47
}
48
48
49
49
pub fn use_item ( use_tree : ast:: UseTree ) -> ast:: UseItem {
50
- ast_from_text ( & format ! ( "use {};" , use_tree. syntax ( ) ) )
50
+ ast_from_text ( & format ! ( "use {};" , use_tree) )
51
51
}
52
52
53
53
pub fn record_field ( name : ast:: NameRef , expr : Option < ast:: Expr > ) -> ast:: RecordField {
54
54
return match expr {
55
- Some ( expr) => from_text ( & format ! ( "{}: {}" , name. syntax ( ) , expr. syntax ( ) ) ) ,
56
- None => from_text ( & name. syntax ( ) . to_string ( ) ) ,
55
+ Some ( expr) => from_text ( & format ! ( "{}: {}" , name, expr) ) ,
56
+ None => from_text ( & name. to_string ( ) ) ,
57
57
} ;
58
58
59
59
fn from_text ( text : & str ) -> ast:: RecordField {
@@ -67,17 +67,17 @@ pub fn block_expr(
67
67
) -> ast:: BlockExpr {
68
68
let mut text = "{\n " . to_string ( ) ;
69
69
for stmt in stmts. into_iter ( ) {
70
- text += & format ! ( " {}\n " , stmt. syntax ( ) ) ;
70
+ text += & format ! ( " {}\n " , stmt) ;
71
71
}
72
72
if let Some ( tail_expr) = tail_expr {
73
- text += & format ! ( " {}\n " , tail_expr. syntax ( ) )
73
+ text += & format ! ( " {}\n " , tail_expr)
74
74
}
75
75
text += "}" ;
76
76
ast_from_text ( & format ! ( "fn f() {}" , text) )
77
77
}
78
78
79
79
pub fn block_from_expr ( e : ast:: Expr ) -> ast:: Block {
80
- return from_text ( & format ! ( "{{ {} }}" , e. syntax ( ) ) ) ;
80
+ return from_text ( & format ! ( "{{ {} }}" , e) ) ;
81
81
82
82
fn from_text ( text : & str ) -> ast:: Block {
83
83
ast_from_text ( & format ! ( "fn f() {}" , text) )
@@ -94,7 +94,7 @@ pub fn expr_unimplemented() -> ast::Expr {
94
94
expr_from_text ( "unimplemented!()" )
95
95
}
96
96
pub fn expr_path ( path : ast:: Path ) -> ast:: Expr {
97
- expr_from_text ( & path. syntax ( ) . to_string ( ) )
97
+ expr_from_text ( & path. to_string ( ) )
98
98
}
99
99
pub fn expr_continue ( ) -> ast:: Expr {
100
100
expr_from_text ( "continue" )
@@ -106,14 +106,14 @@ pub fn expr_return() -> ast::Expr {
106
106
expr_from_text ( "return" )
107
107
}
108
108
pub fn expr_match ( expr : ast:: Expr , match_arm_list : ast:: MatchArmList ) -> ast:: Expr {
109
- expr_from_text ( & format ! ( "match {} {}" , expr. syntax ( ) , match_arm_list. syntax ( ) ) )
109
+ expr_from_text ( & format ! ( "match {} {}" , expr, match_arm_list) )
110
110
}
111
111
pub fn expr_if ( condition : ast:: Expr , then_branch : ast:: BlockExpr ) -> ast:: Expr {
112
- expr_from_text ( & format ! ( "if {} {}" , condition. syntax ( ) , then_branch. syntax ( ) ) )
112
+ expr_from_text ( & format ! ( "if {} {}" , condition, then_branch) )
113
113
}
114
114
pub fn expr_prefix ( op : SyntaxKind , expr : ast:: Expr ) -> ast:: Expr {
115
115
let token = token ( op) ;
116
- expr_from_text ( & format ! ( "{}{}" , token, expr. syntax ( ) ) )
116
+ expr_from_text ( & format ! ( "{}{}" , token, expr) )
117
117
}
118
118
fn expr_from_text ( text : & str ) -> ast:: Expr {
119
119
ast_from_text ( & format ! ( "const C: () = {};" , text) )
@@ -157,17 +157,17 @@ pub fn tuple_struct_pat(
157
157
path : ast:: Path ,
158
158
pats : impl IntoIterator < Item = ast:: Pat > ,
159
159
) -> ast:: TupleStructPat {
160
- let pats_str = pats. into_iter ( ) . map ( |p| p . syntax ( ) . to_string ( ) ) . join ( ", " ) ;
161
- return from_text ( & format ! ( "{}({})" , path. syntax ( ) , pats_str) ) ;
160
+ let pats_str = pats. into_iter ( ) . join ( ", " ) ;
161
+ return from_text ( & format ! ( "{}({})" , path, pats_str) ) ;
162
162
163
163
fn from_text ( text : & str ) -> ast:: TupleStructPat {
164
164
ast_from_text ( & format ! ( "fn f({}: ())" , text) )
165
165
}
166
166
}
167
167
168
168
pub fn record_pat ( path : ast:: Path , pats : impl IntoIterator < Item = ast:: Pat > ) -> ast:: RecordPat {
169
- let pats_str = pats. into_iter ( ) . map ( |p| p . syntax ( ) . to_string ( ) ) . join ( ", " ) ;
170
- return from_text ( & format ! ( "{} {{ {} }}" , path. syntax ( ) , pats_str) ) ;
169
+ let pats_str = pats. into_iter ( ) . join ( ", " ) ;
170
+ return from_text ( & format ! ( "{} {{ {} }}" , path, pats_str) ) ;
171
171
172
172
fn from_text ( text : & str ) -> ast:: RecordPat {
173
173
ast_from_text ( & format ! ( "fn f({}: ())" , text) )
@@ -176,16 +176,15 @@ pub fn record_pat(path: ast::Path, pats: impl IntoIterator<Item = ast::Pat>) ->
176
176
177
177
/// Returns a `BindPat` if the path has just one segment, a `PathPat` otherwise.
178
178
pub fn path_pat ( path : ast:: Path ) -> ast:: Pat {
179
- let path_str = path. syntax ( ) . text ( ) . to_string ( ) ;
180
- return from_text ( path_str. as_str ( ) ) ;
179
+ return from_text ( & path. to_string ( ) ) ;
181
180
fn from_text ( text : & str ) -> ast:: Pat {
182
181
ast_from_text ( & format ! ( "fn f({}: ())" , text) )
183
182
}
184
183
}
185
184
186
185
pub fn match_arm ( pats : impl IntoIterator < Item = ast:: Pat > , expr : ast:: Expr ) -> ast:: MatchArm {
187
- let pats_str = pats. into_iter ( ) . map ( |p| p . syntax ( ) . to_string ( ) ) . join ( " | " ) ;
188
- return from_text ( & format ! ( "{} => {}" , pats_str, expr. syntax ( ) ) ) ;
186
+ let pats_str = pats. into_iter ( ) . join ( " | " ) ;
187
+ return from_text ( & format ! ( "{} => {}" , pats_str, expr) ) ;
189
188
190
189
fn from_text ( text : & str ) -> ast:: MatchArm {
191
190
ast_from_text ( & format ! ( "fn f() {{ match () {{{}}} }}" , text) )
@@ -212,16 +211,16 @@ pub fn where_pred(
212
211
path : ast:: Path ,
213
212
bounds : impl IntoIterator < Item = ast:: TypeBound > ,
214
213
) -> ast:: WherePred {
215
- let bounds = bounds. into_iter ( ) . map ( |b| b . syntax ( ) . to_string ( ) ) . join ( " + " ) ;
216
- return from_text ( & format ! ( "{}: {}" , path. syntax ( ) , bounds) ) ;
214
+ let bounds = bounds. into_iter ( ) . join ( " + " ) ;
215
+ return from_text ( & format ! ( "{}: {}" , path, bounds) ) ;
217
216
218
217
fn from_text ( text : & str ) -> ast:: WherePred {
219
218
ast_from_text ( & format ! ( "fn f() where {} {{ }}" , text) )
220
219
}
221
220
}
222
221
223
222
pub fn where_clause ( preds : impl IntoIterator < Item = ast:: WherePred > ) -> ast:: WhereClause {
224
- let preds = preds. into_iter ( ) . map ( |p| p . syntax ( ) . to_string ( ) ) . join ( ", " ) ;
223
+ let preds = preds. into_iter ( ) . join ( ", " ) ;
225
224
return from_text ( preds. as_str ( ) ) ;
226
225
227
226
fn from_text ( text : & str ) -> ast:: WhereClause {
@@ -231,13 +230,13 @@ pub fn where_clause(preds: impl IntoIterator<Item = ast::WherePred>) -> ast::Whe
231
230
232
231
pub fn let_stmt ( pattern : ast:: Pat , initializer : Option < ast:: Expr > ) -> ast:: LetStmt {
233
232
let text = match initializer {
234
- Some ( it) => format ! ( "let {} = {};" , pattern. syntax ( ) , it. syntax ( ) ) ,
235
- None => format ! ( "let {};" , pattern. syntax ( ) ) ,
233
+ Some ( it) => format ! ( "let {} = {};" , pattern, it) ,
234
+ None => format ! ( "let {};" , pattern) ,
236
235
} ;
237
236
ast_from_text ( & format ! ( "fn f() {{ {} }}" , text) )
238
237
}
239
238
pub fn expr_stmt ( expr : ast:: Expr ) -> ast:: ExprStmt {
240
- ast_from_text ( & format ! ( "fn f() {{ {}; }}" , expr. syntax ( ) ) )
239
+ ast_from_text ( & format ! ( "fn f() {{ {}; }}" , expr) )
241
240
}
242
241
243
242
pub fn token ( kind : SyntaxKind ) -> SyntaxToken {
0 commit comments