From 11c31bb1d390c2a32e7546ab303835bfa1d48b6a Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 20 Feb 2019 01:09:52 +0000 Subject: [PATCH] Add ParamConst Co-Authored-By: Gabriel Smith --- src/librustc/ty/sty.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 3fd2e38a3d3..2f77ad2f180 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1061,6 +1061,26 @@ impl<'a, 'gcx, 'tcx> ParamTy { } } +#[derive(Copy, Clone, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +pub struct ParamConst { + pub index: u32, + pub name: InternedString, +} + +impl<'a, 'gcx, 'tcx> ParamConst { + pub fn new(index: u32, name: InternedString) -> ParamConst { + ParamConst { index, name } + } + + pub fn for_def(def: &ty::GenericParamDef) -> ParamConst { + ParamConst::new(def.index, def.name) + } + + pub fn to_const(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, ty: Ty<'tcx>) -> &'tcx LazyConst<'tcx> { + tcx.mk_const_param(self.index, self.name, ty) + } +} + /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: