diff options
| -rw-r--r-- | src/librustc/ty/mod.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1f897d29a1e..bd3dd78c9bb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -837,7 +837,8 @@ pub enum GenericParamDefKind { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: Option<hir::SyntheticTyParamKind>, - } + }, + Const, } #[derive(Clone, RustcEncodable, RustcDecodable)] @@ -880,6 +881,7 @@ impl GenericParamDef { pub struct GenericParamCount { pub lifetimes: usize, pub types: usize, + pub consts: usize, } /// Information about the formal type/lifetime parameters associated @@ -915,6 +917,7 @@ impl<'a, 'gcx, 'tcx> Generics { match param.kind { GenericParamDefKind::Lifetime => own_counts.lifetimes += 1, GenericParamDefKind::Type { .. } => own_counts.types += 1, + GenericParamDefKind::Const => own_counts.consts += 1, }; } @@ -924,7 +927,7 @@ impl<'a, 'gcx, 'tcx> Generics { pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool { for param in &self.params { match param.kind { - GenericParamDefKind::Type { .. } => return true, + GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => return true, GenericParamDefKind::Lifetime => {} } } @@ -944,7 +947,7 @@ impl<'a, 'gcx, 'tcx> Generics { if let Some(index) = param.index.checked_sub(self.parent_count as u32) { let param = &self.params[index as usize]; match param.kind { - ty::GenericParamDefKind::Lifetime => param, + GenericParamDefKind::Lifetime => param, _ => bug!("expected lifetime parameter, but found another generic parameter") } } else { @@ -961,7 +964,7 @@ impl<'a, 'gcx, 'tcx> Generics { if let Some(index) = param.idx.checked_sub(self.parent_count as u32) { let param = &self.params[index as usize]; match param.kind { - ty::GenericParamDefKind::Type {..} => param, + GenericParamDefKind::Type { .. } => param, _ => bug!("expected type parameter, but found another generic parameter") } } else { @@ -969,6 +972,23 @@ impl<'a, 'gcx, 'tcx> Generics { .type_param(param, tcx) } } + + /// Returns the `ConstParameterDef` associated with this `ParamConst`. + pub fn const_param(&'tcx self, + param: &ParamConst, + tcx: TyCtxt<'a, 'gcx, 'tcx>) + -> &GenericParamDef { + if let Some(index) = param.index.checked_sub(self.parent_count as u32) { + let param = &self.params[index as usize]; + match param.kind { + GenericParamDefKind::Const => param, + _ => bug!("expected const parameter, but found another generic parameter") + } + } else { + tcx.generics_of(self.parent.expect("parent_count>0 but no parent?")) + .const_param(param, tcx) + } + } } /// Bounds on generics. |
