about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-02-05 16:50:00 +0100
committervarkor <github@varkor.com>2019-02-07 15:02:16 +0100
commitd7695abb7667d2e8b7a010282ad5f44abbc58a58 (patch)
tree77bb6c0c52f6bfba98b5cbb609666370c644803c /src/libsyntax
parent0a8d98a270da057975d3cc552a4bb5f0bda5a3af (diff)
downloadrust-d7695abb7667d2e8b7a010282ad5f44abbc58a58.tar.gz
rust-d7695abb7667d2e8b7a010282ad5f44abbc58a58.zip
Support const generics in derive
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/build.rs20
1 files changed, 19 insertions, 1 deletions
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::TypeBinding>)
                 -> (ast::QSelf, ast::Path);
 
-    // types
+    // types and consts
     fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy;
 
     fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty>;
     fn ty_path(&self, path: ast::Path) -> P<ast::Ty>;
     fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
+    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<ast::Ty>,
@@ -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<ast::Ty>,