@@ -40,6 +40,18 @@ pub trait AstBuilder {
4040 bindings : Vec < P < ast:: TypeBinding > > )
4141 -> ast:: Path ;
4242
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+
4355 // types
4456 fn ty_mt ( & self , ty : P < ast:: Ty > , mutbl : ast:: Mutability ) -> ast:: MutTy ;
4557
@@ -102,6 +114,7 @@ pub trait AstBuilder {
102114 // expressions
103115 fn expr ( & self , span : Span , node : ast:: Expr_ ) -> P < ast:: Expr > ;
104116 fn expr_path ( & self , path : ast:: Path ) -> P < ast:: Expr > ;
117+ fn expr_qpath ( & self , span : Span , qpath : P < ast:: QPath > ) -> P < ast:: Expr > ;
105118 fn expr_ident ( & self , span : Span , id : ast:: Ident ) -> P < ast:: Expr > ;
106119
107120 fn expr_self ( & self , span : Span ) -> P < ast:: Expr > ;
@@ -330,6 +343,44 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
330343 }
331344 }
332345
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+
333384 fn ty_mt ( & self , ty : P < ast:: Ty > , mutbl : ast:: Mutability ) -> ast:: MutTy {
334385 ast:: MutTy {
335386 ty : ty,
@@ -554,6 +605,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
554605 self . expr ( path. span , ast:: ExprPath ( path) )
555606 }
556607
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+
557613 fn expr_ident ( & self , span : Span , id : ast:: Ident ) -> P < ast:: Expr > {
558614 self . expr_path ( self . path_ident ( span, id) )
559615 }
0 commit comments