@@ -15,7 +15,11 @@ use parser::{Edition, T};
15
15
use rowan:: NodeOrToken ;
16
16
use stdx:: { format_to, format_to_acc, never} ;
17
17
18
- use crate :: { ast, utils:: is_raw_identifier, AstNode , SourceFile , SyntaxKind , SyntaxToken } ;
18
+ use crate :: {
19
+ ast:: { self , Param } ,
20
+ utils:: is_raw_identifier,
21
+ AstNode , SourceFile , SyntaxKind , SyntaxToken ,
22
+ } ;
19
23
20
24
/// While the parent module defines basic atomic "constructors", the `ext`
21
25
/// module defines shortcuts for common things.
@@ -198,6 +202,38 @@ pub fn ty_alias(
198
202
ast_from_text ( & s)
199
203
}
200
204
205
+ pub fn ty_fn_ptr < I : Iterator < Item = Param > > (
206
+ for_lifetime_list : Option < ast:: GenericParamList > ,
207
+ is_unsafe : bool ,
208
+ abi : Option < ast:: Abi > ,
209
+ params : I ,
210
+ ret_type : Option < ast:: RetType > ,
211
+ ) -> ast:: FnPtrType {
212
+ let mut s = String :: from ( "type __ = " ) ;
213
+
214
+ if let Some ( list) = for_lifetime_list {
215
+ format_to ! ( s, "for{} " , list) ;
216
+ }
217
+
218
+ if is_unsafe {
219
+ s. push_str ( "unsafe " ) ;
220
+ }
221
+
222
+ if let Some ( abi) = abi {
223
+ format_to ! ( s, "{} " , abi)
224
+ }
225
+
226
+ s. push_str ( "fn" ) ;
227
+
228
+ format_to ! ( s, "({})" , params. map( |p| p. to_string( ) ) . join( ", " ) ) ;
229
+
230
+ if let Some ( ret_type) = ret_type {
231
+ format_to ! ( s, " {}" , ret_type) ;
232
+ }
233
+
234
+ ast_from_text ( & s)
235
+ }
236
+
201
237
pub fn assoc_item_list ( ) -> ast:: AssocItemList {
202
238
ast_from_text ( "impl C for D {}" )
203
239
}
@@ -862,6 +898,10 @@ pub fn item_const(
862
898
ast_from_text ( & format ! ( "{visibility} const {name}: {ty} = {expr};" ) )
863
899
}
864
900
901
+ pub fn unnamed_param ( ty : ast:: Type ) -> ast:: Param {
902
+ ast_from_text ( & format ! ( "fn f({ty}) {{ }}" ) )
903
+ }
904
+
865
905
pub fn param ( pat : ast:: Pat , ty : ast:: Type ) -> ast:: Param {
866
906
ast_from_text ( & format ! ( "fn f({pat}: {ty}) {{ }}" ) )
867
907
}
0 commit comments