From 9e213385c9d06db3c8ca20812779e2b8f8ad2c71 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 30 Mar 2019 13:25:53 +0300 Subject: switch to new rowan --- crates/ra_hir/src/expr.rs | 12 ++---------- crates/ra_hir/src/source_binder.rs | 8 ++++---- crates/ra_hir/src/ty/tests.rs | 14 ++++++-------- 3 files changed, 12 insertions(+), 22 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index a85422955..2ff4139f9 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -726,13 +726,7 @@ impl ExprCollector { self.alloc_expr(Expr::Array { exprs }, syntax_ptr) } ast::ExprKind::Literal(e) => { - let child = if let Some(child) = e.literal_expr() { - child - } else { - return self.alloc_expr(Expr::Missing, syntax_ptr); - }; - - let lit = match child.flavor() { + let lit = match e.flavor() { LiteralFlavor::IntNumber { suffix } => { let known_name = suffix .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known)); @@ -874,9 +868,7 @@ impl ExprCollector { fn collect_fn_body(&mut self, node: &ast::FnDef) { if let Some(param_list) = node.param_list() { if let Some(self_param) = param_list.self_param() { - let self_param = SyntaxNodePtr::new( - self_param.self_kw().expect("self param without self keyword").syntax(), - ); + let self_param = SyntaxNodePtr::new(self_param.syntax()); let param_pat = self.alloc_pat( Pat::Bind { name: Name::self_param(), diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 9dae4c3d1..54dc27399 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -9,7 +9,7 @@ use ra_db::{FileId, FilePosition}; use ra_syntax::{ SyntaxNode, ast::{self, AstNode, NameOwner}, - algo::{find_node_at_offset, find_leaf_at_offset}, + algo::{find_node_at_offset, find_token_at_offset}, }; use crate::{ @@ -155,9 +155,9 @@ pub fn trait_from_module( pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { let file_id = position.file_id; let file = db.parse(file_id); - find_leaf_at_offset(file.syntax(), position.offset) - .find_map(|node| { - node.ancestors().find_map(|node| { + find_token_at_offset(file.syntax(), position.offset) + .find_map(|token| { + token.parent().ancestors().find_map(|node| { if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { if let Some(func) = function_from_child_node(db, file_id, node) { let scopes = func.scopes(db); diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 655f3c522..943c5499b 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -2251,14 +2251,12 @@ fn infer(content: &str) -> String { types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); for (syntax_ptr, ty) in &types { let node = syntax_ptr.to_node(&source_file); - write!( - acc, - "{} '{}': {}\n", - syntax_ptr.range(), - ellipsize(node.text().to_string().replace("\n", " "), 15), - ty.display(&db) - ) - .unwrap(); + let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) { + (self_param.self_kw_token().range(), "self".to_string()) + } else { + (syntax_ptr.range(), node.text().to_string().replace("\n", " ")) + }; + write!(acc, "{} '{}': {}\n", range, ellipsize(text, 15), ty.display(&db)).unwrap(); } } acc.truncate(acc.trim_end().len()); -- cgit v1.2.3