Add method to get generic parameters in a type

This commit is contained in:
Ryo Yoshida 2023-01-31 19:26:08 +09:00
parent 0df70d37fc
commit 32955c30cd
No known key found for this signature in database
GPG key ID: E25698A930586171
2 changed files with 76 additions and 1 deletions

View file

@ -3599,6 +3599,14 @@ impl Type {
_ => None,
}
}
/// Returns unique `GenericParam`s contained in this type.
pub fn generic_params(&self, db: &dyn HirDatabase) -> FxHashSet<GenericParam> {
hir_ty::collect_placeholders(&self.ty, db)
.into_iter()
.map(|id| TypeOrConstParam { id }.split(db).either_into())
.collect()
}
}
#[derive(Debug)]