Skip to content

Commit 12bf008

Browse files
committed
Adds a param_idx helper
1 parent 2dfbec1 commit 12bf008

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,8 @@ impl TypeParam {
992992

993993
pub fn default(self, db: &dyn HirDatabase) -> Option<Ty> {
994994
let params = db.generic_defaults(self.id.parent);
995-
let local_idx: u32 = self.id.local_id.into_raw().into();
996-
params.get(local_idx as usize).map(|d| d.clone())
995+
let local_idx = hir_ty::param_idx(db, self.id)?;
996+
params.get(local_idx).map(|d| d.clone())
997997
}
998998
}
999999

crates/ra_hir_ty/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ impl Substs {
427427
}
428428
}
429429

430+
/// Return an index of a parameter in the generic type parameter list by it's id.
431+
pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
432+
generics(db.upcast(), id.parent).param_idx(id)
433+
}
434+
430435
#[derive(Debug, Clone)]
431436
pub struct SubstsBuilder {
432437
vec: Vec<Ty>,

0 commit comments

Comments
 (0)