Adds a param_idx helper

This commit is contained in:
Fedor Sakharov 2020-05-14 13:47:36 +03:00
parent 2dfbec149f
commit 12bf008ab1
No known key found for this signature in database
GPG key ID: 93D436E666BF0FEE
2 changed files with 7 additions and 2 deletions

View file

@ -992,8 +992,8 @@ impl TypeParam {
pub fn default(self, db: &dyn HirDatabase) -> Option<Ty> {
let params = db.generic_defaults(self.id.parent);
let local_idx: u32 = self.id.local_id.into_raw().into();
params.get(local_idx as usize).map(|d| d.clone())
let local_idx = hir_ty::param_idx(db, self.id)?;
params.get(local_idx).map(|d| d.clone())
}
}

View file

@ -427,6 +427,11 @@ impl Substs {
}
}
/// Return an index of a parameter in the generic type parameter list by it's id.
pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
generics(db.upcast(), id.parent).param_idx(id)
}
#[derive(Debug, Clone)]
pub struct SubstsBuilder {
vec: Vec<Ty>,