expose hir::Type::type_paramters

Used to get E parameter from `Result<T, E>`
This commit is contained in:
Vladyslav Katasonov 2021-02-13 21:46:21 +03:00
parent 4be260d693
commit 37a8cec638
2 changed files with 17 additions and 24 deletions

View file

@ -1802,6 +1802,18 @@ impl Type {
None
}
pub fn type_parameters(&self) -> impl Iterator<Item = Type> + '_ {
let ty = self.ty.value.strip_references();
let substs = match ty {
Ty::Apply(apply_ty) => &apply_ty.parameters,
Ty::Opaque(opaque_ty) => &opaque_ty.parameters,
_ => return Either::Left(iter::empty()),
};
let iter = substs.iter().map(move |ty| self.derived(ty.clone()));
Either::Right(iter)
}
pub fn iterate_method_candidates<T>(
&self,
db: &dyn HirDatabase,