From 6f872113ab05c0a23a8784e54d22b9e0641dde41 Mon Sep 17 00:00:00 2001 From: Hugo van der Wijst Date: Wed, 4 Feb 2015 20:00:28 +0100 Subject: [PATCH] Add QPath construction to ExtCtxt for UFCS support. --- src/libsyntax/ext/build.rs | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 53c35ef34cd..4d618e560c5 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -41,6 +41,18 @@ pub trait AstBuilder { bindings: Vec> ) -> ast::Path; + fn qpath(&self, self_type: P, + trait_ref: P, + ident: ast::Ident ) + -> P; + fn qpath_all(&self, self_type: P, + trait_ref: P, + ident: ast::Ident, + lifetimes: Vec, + types: Vec>, + bindings: Vec> ) + -> P; + // types fn ty_mt(&self, ty: P, mutbl: ast::Mutability) -> ast::MutTy; @@ -103,6 +115,7 @@ pub trait AstBuilder { // expressions fn expr(&self, span: Span, node: ast::Expr_) -> P; fn expr_path(&self, path: ast::Path) -> P; + fn expr_qpath(&self, span: Span, qpath: P) -> P; fn expr_ident(&self, span: Span, id: ast::Ident) -> P; fn expr_self(&self, span: Span) -> P; @@ -331,6 +344,44 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } } + /// Constructs a qualified path. + /// + /// Constructs a path like `::ident`. + fn qpath(&self, + self_type: P, + trait_ref: P, + ident: ast::Ident) + -> P { + self.qpath_all(self_type, trait_ref, ident, Vec::new(), Vec::new(), Vec::new()) + } + + /// Constructs a qualified path. + /// + /// Constructs a path like `::ident`. + fn qpath_all(&self, + self_type: P, + trait_ref: P, + ident: ast::Ident, + lifetimes: Vec, + types: Vec>, + bindings: Vec> ) + -> P { + let segment = ast::PathSegment { + identifier: ident, + parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types), + bindings: OwnedSlice::from_vec(bindings), + }) + }; + + P(ast::QPath { + self_type: self_type, + trait_ref: trait_ref, + item_path: segment, + }) + } + fn ty_mt(&self, ty: P, mutbl: ast::Mutability) -> ast::MutTy { ast::MutTy { ty: ty, @@ -554,6 +605,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(path.span, ast::ExprPath(path)) } + /// Constructs a QPath expression. + fn expr_qpath(&self, span: Span, qpath: P) -> P { + self.expr(span, ast::ExprQPath(qpath)) + } + fn expr_ident(&self, span: Span, id: ast::Ident) -> P { self.expr_path(self.path_ident(span, id)) }