@@ -40,6 +40,18 @@ pub trait AstBuilder {
40
40
bindings : Vec < P < ast:: TypeBinding > > )
41
41
-> ast:: Path ;
42
42
43
+ fn qpath ( & self , self_type : P < ast:: Ty > ,
44
+ trait_ref : P < ast:: TraitRef > ,
45
+ ident : ast:: Ident )
46
+ -> P < ast:: QPath > ;
47
+ fn qpath_all ( & self , self_type : P < ast:: Ty > ,
48
+ trait_ref : P < ast:: TraitRef > ,
49
+ ident : ast:: Ident ,
50
+ lifetimes : Vec < ast:: Lifetime > ,
51
+ types : Vec < P < ast:: Ty > > ,
52
+ bindings : Vec < P < ast:: TypeBinding > > )
53
+ -> P < ast:: QPath > ;
54
+
43
55
// types
44
56
fn ty_mt ( & self , ty : P < ast:: Ty > , mutbl : ast:: Mutability ) -> ast:: MutTy ;
45
57
@@ -102,6 +114,7 @@ pub trait AstBuilder {
102
114
// expressions
103
115
fn expr ( & self , span : Span , node : ast:: Expr_ ) -> P < ast:: Expr > ;
104
116
fn expr_path ( & self , path : ast:: Path ) -> P < ast:: Expr > ;
117
+ fn expr_qpath ( & self , span : Span , qpath : P < ast:: QPath > ) -> P < ast:: Expr > ;
105
118
fn expr_ident ( & self , span : Span , id : ast:: Ident ) -> P < ast:: Expr > ;
106
119
107
120
fn expr_self ( & self , span : Span ) -> P < ast:: Expr > ;
@@ -330,6 +343,44 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
330
343
}
331
344
}
332
345
346
+ /// Constructs a qualified path.
347
+ ///
348
+ /// Constructs a path like `<self_type as trait_ref>::ident`.
349
+ fn qpath ( & self ,
350
+ self_type : P < ast:: Ty > ,
351
+ trait_ref : P < ast:: TraitRef > ,
352
+ ident : ast:: Ident )
353
+ -> P < ast:: QPath > {
354
+ self . qpath_all ( self_type, trait_ref, ident, Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) )
355
+ }
356
+
357
+ /// Constructs a qualified path.
358
+ ///
359
+ /// Constructs a path like `<self_type as trait_ref>::ident<a, T, A=Bar>`.
360
+ fn qpath_all ( & self ,
361
+ self_type : P < ast:: Ty > ,
362
+ trait_ref : P < ast:: TraitRef > ,
363
+ ident : ast:: Ident ,
364
+ lifetimes : Vec < ast:: Lifetime > ,
365
+ types : Vec < P < ast:: Ty > > ,
366
+ bindings : Vec < P < ast:: TypeBinding > > )
367
+ -> P < ast:: QPath > {
368
+ let segment = ast:: PathSegment {
369
+ identifier : ident,
370
+ parameters : ast:: AngleBracketedParameters ( ast:: AngleBracketedParameterData {
371
+ lifetimes : lifetimes,
372
+ types : OwnedSlice :: from_vec ( types) ,
373
+ bindings : OwnedSlice :: from_vec ( bindings) ,
374
+ } )
375
+ } ;
376
+
377
+ P ( ast:: QPath {
378
+ self_type : self_type,
379
+ trait_ref : trait_ref,
380
+ item_path : segment,
381
+ } )
382
+ }
383
+
333
384
fn ty_mt ( & self , ty : P < ast:: Ty > , mutbl : ast:: Mutability ) -> ast:: MutTy {
334
385
ast:: MutTy {
335
386
ty : ty,
@@ -554,6 +605,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
554
605
self . expr ( path. span , ast:: ExprPath ( path) )
555
606
}
556
607
608
+ /// Constructs a QPath expression.
609
+ fn expr_qpath ( & self , span : Span , qpath : P < ast:: QPath > ) -> P < ast:: Expr > {
610
+ self . expr ( span, ast:: ExprQPath ( qpath) )
611
+ }
612
+
557
613
fn expr_ident ( & self , span : Span , id : ast:: Ident ) -> P < ast:: Expr > {
558
614
self . expr_path ( self . path_ident ( span, id) )
559
615
}
0 commit comments