Skip to content

Commit 6f87211

Browse files
committed
Add QPath construction to ExtCtxt for UFCS support.
1 parent 3ae76d5 commit 6f87211

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/libsyntax/ext/build.rs

+56
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ pub trait AstBuilder {
4141
bindings: Vec<P<ast::TypeBinding>> )
4242
-> ast::Path;
4343

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+
4456
// types
4557
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
4658

@@ -103,6 +115,7 @@ pub trait AstBuilder {
103115
// expressions
104116
fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr>;
105117
fn expr_path(&self, path: ast::Path) -> P<ast::Expr>;
118+
fn expr_qpath(&self, span: Span, qpath: P<ast::QPath>) -> P<ast::Expr>;
106119
fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
107120

108121
fn expr_self(&self, span: Span) -> P<ast::Expr>;
@@ -331,6 +344,44 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
331344
}
332345
}
333346

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+
334385
fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
335386
ast::MutTy {
336387
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

Comments
 (0)