From c9cfd57eeaa53657c0af7b9c4ba74d6b7b9889ed Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Jul 2019 20:04:34 +0300 Subject: switch to upstream rowan's API --- crates/ra_syntax/src/ast/expr_extensions.rs | 13 +++++-------- crates/ra_syntax/src/ast/extensions.rs | 5 +---- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 139bd3ec0..f9190d877 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -2,7 +2,7 @@ use crate::{ ast::{self, child_opt, children, AstChildren, AstNode}, - SmolStr, SyntaxElement, + SmolStr, SyntaxKind::*, SyntaxToken, T, }; @@ -229,14 +229,11 @@ pub enum LiteralKind { impl ast::Literal { pub fn token(&self) -> SyntaxToken { - let elem = self - .syntax() + self.syntax() .children_with_tokens() - .find(|e| e.kind() != ATTR && !e.kind().is_trivia()); - match elem { - Some(SyntaxElement::Token(token)) => token, - _ => unreachable!(), - } + .find(|e| e.kind() != ATTR && !e.kind().is_trivia()) + .and_then(|e| e.into_token()) + .unwrap() } pub fn kind(&self) -> LiteralKind { diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 753fc42c6..d4873b39a 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -24,10 +24,7 @@ impl ast::NameRef { } fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { - match node.0.green().children().first() { - Some(rowan::GreenElement::Token(it)) => it.text(), - _ => panic!(), - } + node.green().children().first().and_then(|it| it.as_token()).unwrap().text() } impl ast::Attr { -- cgit v1.2.3