From f9d9e0a1f75b48813fe816a1e2a6c30146a36503 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 19 Jul 2019 15:53:16 +0300 Subject: several highlighting cleanups * make stuff more type-safe by using `BindPat` instead of just `Pat` * don't add `mut` into binding hash * reset shadow counter when we enter a function --- crates/ra_hir/src/source_binder.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/source_binder.rs') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index e7bc4df97..55eb7da35 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -181,7 +181,7 @@ pub enum PathResolution { /// An item Def(crate::ModuleDef), /// A local binding (only value namespace) - LocalBinding(Either, AstPtr>), + LocalBinding(Either, AstPtr>), /// A generic parameter GenericParam(u32), SelfType(crate::ImplBlock), @@ -307,7 +307,18 @@ impl SourceAnalyzer { let res = match res { crate::Resolution::Def(it) => PathResolution::Def(it), crate::Resolution::LocalBinding(it) => { - PathResolution::LocalBinding(self.body_source_map.as_ref()?.pat_syntax(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), + }; + PathResolution::LocalBinding(pat_ptr) } crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it), crate::Resolution::SelfType(it) => PathResolution::SelfType(it), -- cgit v1.2.3