From 37a8cec6386d57e76b3067af48c78867aa9922ed Mon Sep 17 00:00:00 2001 From: Vladyslav Katasonov Date: Sat, 13 Feb 2021 21:46:21 +0300 Subject: expose hir::Type::type_paramters Used to get E parameter from `Result` --- crates/hir/src/code_model.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/hir/src') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 35b532602..7d43d4097 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1802,6 +1802,18 @@ impl Type { None } + pub fn type_parameters(&self) -> impl Iterator + '_ { + 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( &self, db: &dyn HirDatabase, -- cgit v1.2.3