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_syntax/src/ptr.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 016256075..25824722f 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -60,6 +60,17 @@ impl AstPtr { pub fn syntax_node_ptr(self) -> SyntaxNodePtr { self.raw } + + // FIXME: extend AstNode to do this safely + pub fn cast_checking_kind( + self, + cond: impl FnOnce(SyntaxKind) -> bool, + ) -> Option> { + if !cond(self.raw.kind()) { + return None; + } + Some(AstPtr { raw: self.raw, _ty: PhantomData }) + } } impl From> for SyntaxNodePtr { -- cgit v1.2.3