Add Const generic param to ty
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
This commit is contained in:
parent
f22dca0a1b
commit
62f23c2b0b
1 changed files with 24 additions and 4 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue