From 5c594bcb48f01bdcf3068f72cefffda337a03533 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 19 Jul 2019 18:22:00 +0300 Subject: cleanup casts --- crates/ra_hir/src/either.rs | 6 ++++++ crates/ra_hir/src/source_binder.rs | 14 +++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs index 71c53ebc0..439e6ec87 100644 --- a/crates/ra_hir/src/either.rs +++ b/crates/ra_hir/src/either.rs @@ -25,6 +25,12 @@ impl Either { Either::B(b) => Either::B(f2(b)), } } + pub fn map_a(self, f: F) -> Either + where + F: FnOnce(A) -> U, + { + self.map(f, |it| it) + } pub fn a(self) -> Option { match self { Either::A(it) => Some(it), diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 55eb7da35..df67d2c39 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -309,15 +309,11 @@ impl SourceAnalyzer { crate::Resolution::LocalBinding(it) => { // We get a `PatId` from resolver, but it actually can only // point at `BindPat`, and not at the arbitrary pattern. - let pat_ptr = self.body_source_map.as_ref()?.pat_syntax(it)?; - let pat_ptr = match pat_ptr { - Either::A(pat) => { - let pat: AstPtr = - pat.cast_checking_kind(|kind| kind == BIND_PAT).unwrap(); - Either::A(pat) - } - Either::B(self_param) => Either::B(self_param), - }; + let pat_ptr = self + .body_source_map + .as_ref()? + .pat_syntax(it)? + .map_a(|ptr| ptr.cast::().unwrap()); PathResolution::LocalBinding(pat_ptr) } crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it), -- cgit v1.2.3