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, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e6fe125da9f..4678c752045 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -560,6 +560,7 @@ impl<'a> TraitDef<'a> { cx.typaram(self.span, param.ident, vec![], bounds, None) } + GenericParamKind::Const { .. } => param.clone(), })); // and similarly for where clauses @@ -657,6 +658,9 @@ impl<'a> TraitDef<'a> { GenericParamKind::Type { .. } => { GenericArg::Type(cx.ty_ident(self.span, param.ident)) } + GenericParamKind::Const { .. } => { + GenericArg::Const(cx.const_ident(self.span, param.ident)) + } }).collect(); // Create the type of `self`. diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index ea6e07922b2..100ec0057ee 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -94,7 +94,7 @@ impl<'a> Path<'a> { } } -/// A type. Supports pointers, Self, and literals +/// A type. Supports pointers, Self, and literals. #[derive(Clone)] pub enum Ty<'a> { Self_, @@ -107,6 +107,13 @@ pub enum Ty<'a> { Tuple(Vec>), } +/// A const expression. Supports literals and blocks. +#[derive(Clone, Eq, PartialEq)] +pub enum Const { + Literal, + Block, +} + pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { Borrowed(None, ast::Mutability::Immutable) } @@ -180,6 +187,9 @@ impl<'a> Ty<'a> { GenericParamKind::Type { .. } => { GenericArg::Type(cx.ty_ident(span, param.ident)) } + GenericParamKind::Const { .. } => { + GenericArg::Const(cx.const_ident(span, param.ident)) + } }).collect(); cx.path_all(span, false, vec![self_ty], params, vec![])