diff options
author | Vladyslav Katasonov <[email protected]> | 2021-02-13 18:46:21 +0000 |
---|---|---|
committer | Vladyslav Katasonov <[email protected]> | 2021-02-13 19:04:52 +0000 |
commit | 37a8cec6386d57e76b3067af48c78867aa9922ed (patch) | |
tree | 3e5a3046b345a1586132dd8b70f91c84da5e5951 /crates/hir/src/code_model.rs | |
parent | 4be260d693babea7d32fead0ca10762a64557aaf (diff) |
expose hir::Type::type_paramters
Used to get E parameter from `Result<T, E>`
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r-- | crates/hir/src/code_model.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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 { | |||
1802 | None | 1802 | None |
1803 | } | 1803 | } |
1804 | 1804 | ||
1805 | pub fn type_parameters(&self) -> impl Iterator<Item = Type> + '_ { | ||
1806 | let ty = self.ty.value.strip_references(); | ||
1807 | let substs = match ty { | ||
1808 | Ty::Apply(apply_ty) => &apply_ty.parameters, | ||
1809 | Ty::Opaque(opaque_ty) => &opaque_ty.parameters, | ||
1810 | _ => return Either::Left(iter::empty()), | ||
1811 | }; | ||
1812 | |||
1813 | let iter = substs.iter().map(move |ty| self.derived(ty.clone())); | ||
1814 | Either::Right(iter) | ||
1815 | } | ||
1816 | |||
1805 | pub fn iterate_method_candidates<T>( | 1817 | pub fn iterate_method_candidates<T>( |
1806 | &self, | 1818 | &self, |
1807 | db: &dyn HirDatabase, | 1819 | db: &dyn HirDatabase, |