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