diff options
| author | varkor <github@varkor.com> | 2019-02-05 16:50:00 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-02-07 15:02:16 +0100 |
| commit | d7695abb7667d2e8b7a010282ad5f44abbc58a58 (patch) | |
| tree | 77bb6c0c52f6bfba98b5cbb609666370c644803c /src/libsyntax_ext | |
| parent | 0a8d98a270da057975d3cc552a4bb5f0bda5a3af (diff) | |
| download | rust-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_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/ty.rs | 12 |
2 files changed, 15 insertions, 1 deletions
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<Ty<'a>>), } +/// 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![]) |
