From d7695abb7667d2e8b7a010282ad5f44abbc58a58 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Feb 2019 16:50:00 +0100 Subject: Support const generics in derive Co-Authored-By: Gabriel Smith --- src/libsyntax/ext/build.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1e83f6c03ec..6708e3c12a0 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -38,12 +38,14 @@ pub trait AstBuilder { bindings: Vec) -> (ast::QSelf, ast::Path); - // types + // types and consts fn ty_mt(&self, ty: P, mutbl: ast::Mutability) -> ast::MutTy; fn ty(&self, span: Span, ty: ast::TyKind) -> P; fn ty_path(&self, path: ast::Path) -> P; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P; + fn anon_const(&self, span: Span, expr: ast::ExprKind) -> ast::AnonConst; + fn const_ident(&self, span: Span, idents: ast::Ident) -> ast::AnonConst; fn ty_rptr(&self, span: Span, ty: P, @@ -394,6 +396,22 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ty_path(self.path_ident(span, ident)) } + fn anon_const(&self, span: Span, expr: ast::ExprKind) -> ast::AnonConst { + ast::AnonConst { + id: ast::DUMMY_NODE_ID, + value: P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: expr, + span, + attrs: ThinVec::new(), + }) + } + } + + fn const_ident(&self, span: Span, ident: ast::Ident) -> ast::AnonConst { + self.anon_const(span, ast::ExprKind::Path(None, self.path_ident(span, ident))) + } + fn ty_rptr(&self, span: Span, ty: P, -- cgit 1.4.1-3-g733a5