aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs28
-rw-r--r--crates/ra_hir/src/code_model_api.rs8
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs8
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs4
-rw-r--r--crates/ra_hir/src/expr.rs37
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/nameres.rs7
-rw-r--r--crates/ra_hir/src/nameres/raw.rs73
-rw-r--r--crates/ra_hir/src/path.rs13
-rw-r--r--crates/ra_hir/src/source_binder.rs8
-rw-r--r--crates/ra_hir/src/ty/tests.rs14
11 files changed, 111 insertions, 91 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 78ea8976b..e027eedd9 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -6,7 +6,7 @@ use std::sync::Arc;
6use ra_arena::{RawId, Arena, impl_arena_id}; 6use ra_arena::{RawId, Arena, impl_arena_id};
7use ra_syntax::{ 7use ra_syntax::{
8 TreeArc, 8 TreeArc,
9 ast::{self, NameOwner, StructFlavor, TypeAscriptionOwner} 9 ast::{self, NameOwner, StructKind, TypeAscriptionOwner}
10}; 10};
11 11
12use crate::{ 12use crate::{
@@ -47,7 +47,7 @@ pub struct StructData {
47impl StructData { 47impl StructData {
48 fn new(struct_def: &ast::StructDef) -> StructData { 48 fn new(struct_def: &ast::StructDef) -> StructData {
49 let name = struct_def.name().map(|n| n.as_name()); 49 let name = struct_def.name().map(|n| n.as_name());
50 let variant_data = VariantData::new(struct_def.flavor()); 50 let variant_data = VariantData::new(struct_def.kind());
51 let variant_data = Arc::new(variant_data); 51 let variant_data = Arc::new(variant_data);
52 StructData { name, variant_data } 52 StructData { name, variant_data }
53 } 53 }
@@ -94,7 +94,7 @@ impl EnumData {
94 let variants = variants(&*enum_def) 94 let variants = variants(&*enum_def)
95 .map(|var| EnumVariantData { 95 .map(|var| EnumVariantData {
96 name: var.name().map(|it| it.as_name()), 96 name: var.name().map(|it| it.as_name()),
97 variant_data: Arc::new(VariantData::new(var.flavor())), 97 variant_data: Arc::new(VariantData::new(var.kind())),
98 }) 98 })
99 .collect(); 99 .collect();
100 Arc::new(EnumData { name, variants }) 100 Arc::new(EnumData { name, variants })
@@ -143,9 +143,9 @@ impl VariantData {
143} 143}
144 144
145impl VariantData { 145impl VariantData {
146 fn new(flavor: StructFlavor) -> Self { 146 fn new(flavor: StructKind) -> Self {
147 let inner = match flavor { 147 let inner = match flavor {
148 ast::StructFlavor::Tuple(fl) => { 148 ast::StructKind::Tuple(fl) => {
149 let fields = fl 149 let fields = fl
150 .fields() 150 .fields()
151 .enumerate() 151 .enumerate()
@@ -156,7 +156,7 @@ impl VariantData {
156 .collect(); 156 .collect();
157 VariantDataInner::Tuple(fields) 157 VariantDataInner::Tuple(fields)
158 } 158 }
159 ast::StructFlavor::Named(fl) => { 159 ast::StructKind::Named(fl) => {
160 let fields = fl 160 let fields = fl
161 .fields() 161 .fields()
162 .map(|fd| StructFieldData { 162 .map(|fd| StructFieldData {
@@ -166,7 +166,7 @@ impl VariantData {
166 .collect(); 166 .collect();
167 VariantDataInner::Struct(fields) 167 VariantDataInner::Struct(fields)
168 } 168 }
169 ast::StructFlavor::Unit => VariantDataInner::Unit, 169 ast::StructKind::Unit => VariantDataInner::Unit,
170 }; 170 };
171 VariantData(inner) 171 VariantData(inner)
172 } 172 }
@@ -200,27 +200,27 @@ impl StructField {
200 let fields = var_data.fields().unwrap(); 200 let fields = var_data.fields().unwrap();
201 let ss; 201 let ss;
202 let es; 202 let es;
203 let (file_id, struct_flavor) = match self.parent { 203 let (file_id, struct_kind) = match self.parent {
204 VariantDef::Struct(s) => { 204 VariantDef::Struct(s) => {
205 let (file_id, source) = s.source(db); 205 let (file_id, source) = s.source(db);
206 ss = source; 206 ss = source;
207 (file_id, ss.flavor()) 207 (file_id, ss.kind())
208 } 208 }
209 VariantDef::EnumVariant(e) => { 209 VariantDef::EnumVariant(e) => {
210 let (file_id, source) = e.source(db); 210 let (file_id, source) = e.source(db);
211 es = source; 211 es = source;
212 (file_id, es.flavor()) 212 (file_id, es.kind())
213 } 213 }
214 }; 214 };
215 215
216 let field_sources = match struct_flavor { 216 let field_sources = match struct_kind {
217 ast::StructFlavor::Tuple(fl) => { 217 ast::StructKind::Tuple(fl) => {
218 fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect() 218 fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect()
219 } 219 }
220 ast::StructFlavor::Named(fl) => { 220 ast::StructKind::Named(fl) => {
221 fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect() 221 fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect()
222 } 222 }
223 ast::StructFlavor::Unit => Vec::new(), 223 ast::StructKind::Unit => Vec::new(),
224 }; 224 };
225 let field = field_sources 225 let field = field_sources
226 .into_iter() 226 .into_iter()
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index c3e5e26c3..9e6170440 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -4,7 +4,7 @@ use ra_db::{CrateId, SourceRootId, Edition};
4use ra_syntax::{ast::self, TreeArc}; 4use ra_syntax::{ast::self, TreeArc};
5 5
6use crate::{ 6use crate::{
7 Name, ScopesWithSourceMap, Ty, HirFileId, 7 Name, ScopesWithSourceMap, Ty, HirFileId, ImportSource,
8 HirDatabase, DefDatabase, 8 HirDatabase, DefDatabase,
9 type_ref::TypeRef, 9 type_ref::TypeRef,
10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 10 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
@@ -117,11 +117,7 @@ impl Module {
117 } 117 }
118 118
119 /// Returns the syntax of the last path segment corresponding to this import 119 /// Returns the syntax of the last path segment corresponding to this import
120 pub fn import_source( 120 pub fn import_source(&self, db: &impl HirDatabase, import: ImportId) -> ImportSource {
121 &self,
122 db: &impl HirDatabase,
123 import: ImportId,
124 ) -> TreeArc<ast::PathSegment> {
125 self.import_source_impl(db, import) 121 self.import_source_impl(db, import)
126 } 122 }
127 123
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index 334cb302b..f8bd0f784 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -20,12 +20,12 @@ impl FnSignature {
20 TypeRef::from_ast(type_ref) 20 TypeRef::from_ast(type_ref)
21 } else { 21 } else {
22 let self_type = TypeRef::Path(Name::self_type().into()); 22 let self_type = TypeRef::Path(Name::self_type().into());
23 match self_param.flavor() { 23 match self_param.kind() {
24 ast::SelfParamFlavor::Owned => self_type, 24 ast::SelfParamKind::Owned => self_type,
25 ast::SelfParamFlavor::Ref => { 25 ast::SelfParamKind::Ref => {
26 TypeRef::Reference(Box::new(self_type), Mutability::Shared) 26 TypeRef::Reference(Box::new(self_type), Mutability::Shared)
27 } 27 }
28 ast::SelfParamFlavor::MutRef => { 28 ast::SelfParamKind::MutRef => {
29 TypeRef::Reference(Box::new(self_type), Mutability::Mut) 29 TypeRef::Reference(Box::new(self_type), Mutability::Mut)
30 } 30 }
31 } 31 }
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 0edb8ade5..88dee3a69 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -5,7 +5,7 @@ use crate::{
5 Module, ModuleSource, Name, AstId, 5 Module, ModuleSource, Name, AstId,
6 nameres::{CrateModuleId, ImportId}, 6 nameres::{CrateModuleId, ImportId},
7 HirDatabase, DefDatabase, 7 HirDatabase, DefDatabase,
8 HirFileId, 8 HirFileId, ImportSource,
9}; 9};
10 10
11impl ModuleSource { 11impl ModuleSource {
@@ -72,7 +72,7 @@ impl Module {
72 &self, 72 &self,
73 db: &impl HirDatabase, 73 db: &impl HirDatabase,
74 import: ImportId, 74 import: ImportId,
75 ) -> TreeArc<ast::PathSegment> { 75 ) -> ImportSource {
76 let (file_id, source) = self.definition_source(db); 76 let (file_id, source) = self.definition_source(db);
77 let (_, source_map) = db.raw_items_with_source_map(file_id); 77 let (_, source_map) = db.raw_items_with_source_map(file_id);
78 source_map.get(&source, import) 78 source_map.get(&source, import)
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 51366de0a..b2a237ece 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodePtr, AstPtr, AstNode, 8 SyntaxNodePtr, AstPtr, AstNode,
9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor, TypeAscriptionOwner} 9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind, TypeAscriptionOwner}
10}; 10};
11 11
12use crate::{ 12use crate::{
@@ -515,8 +515,8 @@ impl ExprCollector {
515 let else_branch = e 515 let else_branch = e
516 .else_branch() 516 .else_branch()
517 .map(|b| match b { 517 .map(|b| match b {
518 ast::ElseBranchFlavor::Block(it) => self.collect_block(it), 518 ast::ElseBranch::Block(it) => self.collect_block(it),
519 ast::ElseBranchFlavor::IfExpr(elif) => { 519 ast::ElseBranch::IfExpr(elif) => {
520 let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap(); 520 let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
521 self.collect_expr(expr) 521 self.collect_expr(expr)
522 } 522 }
@@ -532,8 +532,8 @@ impl ExprCollector {
532 let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr())); 532 let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
533 let then_branch = self.collect_block_opt(e.then_branch()); 533 let then_branch = self.collect_block_opt(e.then_branch());
534 let else_branch = e.else_branch().map(|b| match b { 534 let else_branch = e.else_branch().map(|b| match b {
535 ast::ElseBranchFlavor::Block(it) => self.collect_block(it), 535 ast::ElseBranch::Block(it) => self.collect_block(it),
536 ast::ElseBranchFlavor::IfExpr(elif) => { 536 ast::ElseBranch::IfExpr(elif) => {
537 let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap(); 537 let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
538 self.collect_expr(expr) 538 self.collect_expr(expr)
539 } 539 }
@@ -725,14 +725,8 @@ impl ExprCollector {
725 self.alloc_expr(Expr::Array { exprs }, syntax_ptr) 725 self.alloc_expr(Expr::Array { exprs }, syntax_ptr)
726 } 726 }
727 ast::ExprKind::Literal(e) => { 727 ast::ExprKind::Literal(e) => {
728 let child = if let Some(child) = e.literal_expr() { 728 let lit = match e.kind() {
729 child 729 LiteralKind::IntNumber { suffix } => {
730 } else {
731 return self.alloc_expr(Expr::Missing, syntax_ptr);
732 };
733
734 let lit = match child.flavor() {
735 LiteralFlavor::IntNumber { suffix } => {
736 let known_name = suffix 730 let known_name = suffix
737 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known)); 731 .and_then(|it| IntTy::from_suffix(&it).map(UncertainIntTy::Known));
738 732
@@ -741,7 +735,7 @@ impl ExprCollector {
741 known_name.unwrap_or(UncertainIntTy::Unknown), 735 known_name.unwrap_or(UncertainIntTy::Unknown),
742 ) 736 )
743 } 737 }
744 LiteralFlavor::FloatNumber { suffix } => { 738 LiteralKind::FloatNumber { suffix } => {
745 let known_name = suffix 739 let known_name = suffix
746 .and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known)); 740 .and_then(|it| FloatTy::from_suffix(&it).map(UncertainFloatTy::Known));
747 741
@@ -750,13 +744,13 @@ impl ExprCollector {
750 known_name.unwrap_or(UncertainFloatTy::Unknown), 744 known_name.unwrap_or(UncertainFloatTy::Unknown),
751 ) 745 )
752 } 746 }
753 LiteralFlavor::ByteString => Literal::ByteString(Default::default()), 747 LiteralKind::ByteString => Literal::ByteString(Default::default()),
754 LiteralFlavor::String => Literal::String(Default::default()), 748 LiteralKind::String => Literal::String(Default::default()),
755 LiteralFlavor::Byte => { 749 LiteralKind::Byte => {
756 Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8())) 750 Literal::Int(Default::default(), UncertainIntTy::Known(IntTy::u8()))
757 } 751 }
758 LiteralFlavor::Bool => Literal::Bool(Default::default()), 752 LiteralKind::Bool => Literal::Bool(Default::default()),
759 LiteralFlavor::Char => Literal::Char(Default::default()), 753 LiteralKind::Char => Literal::Char(Default::default()),
760 }; 754 };
761 self.alloc_expr(Expr::Literal(lit), syntax_ptr) 755 self.alloc_expr(Expr::Literal(lit), syntax_ptr)
762 } 756 }
@@ -765,6 +759,7 @@ impl ExprCollector {
765 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 759 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
766 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 760 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
767 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 761 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
762 ast::ExprKind::MacroCall(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
768 } 763 }
769 } 764 }
770 765
@@ -883,9 +878,7 @@ impl ExprCollector {
883 fn collect_fn_body(&mut self, node: &ast::FnDef) { 878 fn collect_fn_body(&mut self, node: &ast::FnDef) {
884 if let Some(param_list) = node.param_list() { 879 if let Some(param_list) = node.param_list() {
885 if let Some(self_param) = param_list.self_param() { 880 if let Some(self_param) = param_list.self_param() {
886 let self_param = SyntaxNodePtr::new( 881 let self_param = SyntaxNodePtr::new(self_param.syntax());
887 self_param.self_kw().expect("self param without self keyword").syntax(),
888 );
889 let param_pat = self.alloc_pat( 882 let param_pat = self.alloc_pat(
890 Pat::Bind { 883 Pat::Bind {
891 name: Name::self_param(), 884 name: Name::self_param(),
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 5b6abcf6d..c19450f39 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -56,7 +56,7 @@ pub use self::{
56 name::Name, 56 name::Name,
57 source_id::{AstIdMap, ErasedFileAstId}, 57 source_id::{AstIdMap, ErasedFileAstId},
58 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, HirInterner}, 58 ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, HirInterner},
59 nameres::{PerNs, Namespace}, 59 nameres::{PerNs, Namespace, ImportId, ImportSource},
60 ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay}, 60 ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay},
61 impl_block::{ImplBlock, ImplItem}, 61 impl_block::{ImplBlock, ImplItem},
62 docs::{Docs, Documentation}, 62 docs::{Docs, Documentation},
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 67b9d6986..6f049acfc 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -70,9 +70,12 @@ use crate::{
70 AstId, 70 AstId,
71}; 71};
72 72
73pub(crate) use self::raw::{RawItems, ImportId, ImportSourceMap}; 73pub(crate) use self::raw::{RawItems, ImportSourceMap};
74 74
75pub use self::per_ns::{PerNs, Namespace}; 75pub use self::{
76 per_ns::{PerNs, Namespace},
77 raw::{ImportId, ImportSource},
78};
76 79
77/// Contans all top-level defs from a macro-expanded crate 80/// Contans all top-level defs from a macro-expanded crate
78#[derive(Debug, PartialEq, Eq)] 81#[derive(Debug, PartialEq, Eq)]
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 0936229ac..b7416ede6 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -31,21 +31,43 @@ pub struct RawItems {
31 31
32#[derive(Debug, Default, PartialEq, Eq)] 32#[derive(Debug, Default, PartialEq, Eq)]
33pub struct ImportSourceMap { 33pub struct ImportSourceMap {
34 map: ArenaMap<ImportId, AstPtr<ast::PathSegment>>, 34 map: ArenaMap<ImportId, ImportSourcePtr>,
35}
36
37#[derive(Debug, PartialEq, Eq, Clone, Copy)]
38enum ImportSourcePtr {
39 UseTree(AstPtr<ast::UseTree>),
40 ExternCrate(AstPtr<ast::ExternCrateItem>),
41}
42
43impl ImportSourcePtr {
44 fn to_node(self, file: &SourceFile) -> ImportSource {
45 match self {
46 ImportSourcePtr::UseTree(ptr) => ImportSource::UseTree(ptr.to_node(file).to_owned()),
47 ImportSourcePtr::ExternCrate(ptr) => {
48 ImportSource::ExternCrate(ptr.to_node(file).to_owned())
49 }
50 }
51 }
52}
53
54pub enum ImportSource {
55 UseTree(TreeArc<ast::UseTree>),
56 ExternCrate(TreeArc<ast::ExternCrateItem>),
35} 57}
36 58
37impl ImportSourceMap { 59impl ImportSourceMap {
38 fn insert(&mut self, import: ImportId, segment: &ast::PathSegment) { 60 fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) {
39 self.map.insert(import, AstPtr::new(segment)) 61 self.map.insert(import, ptr)
40 } 62 }
41 63
42 pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> TreeArc<ast::PathSegment> { 64 pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource {
43 let file = match source { 65 let file = match source {
44 ModuleSource::SourceFile(file) => &*file, 66 ModuleSource::SourceFile(file) => &*file,
45 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), 67 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
46 }; 68 };
47 69
48 self.map[import].to_node(file).to_owned() 70 self.map[import].to_node(file)
49 } 71 }
50} 72}
51 73
@@ -256,18 +278,14 @@ impl RawItemsCollector {
256 fn add_use_item(&mut self, current_module: Option<Module>, use_item: &ast::UseItem) { 278 fn add_use_item(&mut self, current_module: Option<Module>, use_item: &ast::UseItem) {
257 let is_prelude = use_item.has_atom_attr("prelude_import"); 279 let is_prelude = use_item.has_atom_attr("prelude_import");
258 280
259 Path::expand_use_item(use_item, |path, segment, alias| { 281 Path::expand_use_item(use_item, |path, use_tree, is_glob, alias| {
260 let import = self.raw_items.imports.alloc(ImportData { 282 let import_data =
261 path, 283 ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false };
262 alias, 284 self.push_import(
263 is_glob: segment.is_none(), 285 current_module,
264 is_prelude, 286 import_data,
265 is_extern_crate: false, 287 ImportSourcePtr::UseTree(AstPtr::new(use_tree)),
266 }); 288 );
267 if let Some(segment) = segment {
268 self.source_map.insert(import, segment)
269 }
270 self.push_item(current_module, RawItem::Import(import))
271 }) 289 })
272 } 290 }
273 291
@@ -279,14 +297,18 @@ impl RawItemsCollector {
279 if let Some(name_ref) = extern_crate.name_ref() { 297 if let Some(name_ref) = extern_crate.name_ref() {
280 let path = Path::from_name_ref(name_ref); 298 let path = Path::from_name_ref(name_ref);
281 let alias = extern_crate.alias().and_then(|a| a.name()).map(AsName::as_name); 299 let alias = extern_crate.alias().and_then(|a| a.name()).map(AsName::as_name);
282 let import = self.raw_items.imports.alloc(ImportData { 300 let import_data = ImportData {
283 path, 301 path,
284 alias, 302 alias,
285 is_glob: false, 303 is_glob: false,
286 is_prelude: false, 304 is_prelude: false,
287 is_extern_crate: true, 305 is_extern_crate: true,
288 }); 306 };
289 self.push_item(current_module, RawItem::Import(import)) 307 self.push_import(
308 current_module,
309 import_data,
310 ImportSourcePtr::ExternCrate(AstPtr::new(extern_crate)),
311 );
290 } 312 }
291 } 313 }
292 314
@@ -303,6 +325,17 @@ impl RawItemsCollector {
303 self.push_item(current_module, RawItem::Macro(m)); 325 self.push_item(current_module, RawItem::Macro(m));
304 } 326 }
305 327
328 fn push_import(
329 &mut self,
330 current_module: Option<Module>,
331 data: ImportData,
332 source: ImportSourcePtr,
333 ) {
334 let import = self.raw_items.imports.alloc(data);
335 self.source_map.insert(import, source);
336 self.push_item(current_module, RawItem::Import(import))
337 }
338
306 fn push_item(&mut self, current_module: Option<Module>, item: RawItem) { 339 fn push_item(&mut self, current_module: Option<Module>, item: RawItem) {
307 match current_module { 340 match current_module {
308 Some(module) => match &mut self.raw_items.modules[module] { 341 Some(module) => match &mut self.raw_items.modules[module] {
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs
index 6cc8104f4..5449cddfd 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir/src/path.rs
@@ -46,7 +46,7 @@ impl Path {
46 /// Calls `cb` with all paths, represented by this use item. 46 /// Calls `cb` with all paths, represented by this use item.
47 pub fn expand_use_item<'a>( 47 pub fn expand_use_item<'a>(
48 item: &'a ast::UseItem, 48 item: &'a ast::UseItem,
49 mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>), 49 mut cb: impl FnMut(Path, &'a ast::UseTree, bool, Option<Name>),
50 ) { 50 ) {
51 if let Some(tree) = item.use_tree() { 51 if let Some(tree) = item.use_tree() {
52 expand_use_tree(None, tree, &mut cb); 52 expand_use_tree(None, tree, &mut cb);
@@ -156,7 +156,7 @@ impl From<Name> for Path {
156fn expand_use_tree<'a>( 156fn expand_use_tree<'a>(
157 prefix: Option<Path>, 157 prefix: Option<Path>,
158 tree: &'a ast::UseTree, 158 tree: &'a ast::UseTree,
159 cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>), 159 cb: &mut impl FnMut(Path, &'a ast::UseTree, bool, Option<Name>),
160) { 160) {
161 if let Some(use_tree_list) = tree.use_tree_list() { 161 if let Some(use_tree_list) = tree.use_tree_list() {
162 let prefix = match tree.path() { 162 let prefix = match tree.path() {
@@ -181,18 +181,15 @@ fn expand_use_tree<'a>(
181 if let Some(segment) = ast_path.segment() { 181 if let Some(segment) = ast_path.segment() {
182 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { 182 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) {
183 if let Some(prefix) = prefix { 183 if let Some(prefix) = prefix {
184 cb(prefix, Some(segment), alias); 184 cb(prefix, tree, false, alias);
185 return; 185 return;
186 } 186 }
187 } 187 }
188 } 188 }
189 } 189 }
190 if let Some(path) = convert_path(prefix, ast_path) { 190 if let Some(path) = convert_path(prefix, ast_path) {
191 if tree.has_star() { 191 let is_glob = tree.has_star();
192 cb(path, None, alias) 192 cb(path, tree, is_glob, alias)
193 } else if let Some(segment) = ast_path.segment() {
194 cb(path, Some(segment), alias)
195 };
196 } 193 }
197 // FIXME: report errors somewhere 194 // FIXME: report errors somewhere
198 // We get here if we do 195 // We get here if we do
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 430dbc522..182ed4c91 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};
9use ra_syntax::{ 9use ra_syntax::{
10 SyntaxNode, 10 SyntaxNode,
11 ast::{self, AstNode, NameOwner}, 11 ast::{self, AstNode, NameOwner},
12 algo::{find_node_at_offset, find_leaf_at_offset}, 12 algo::{find_node_at_offset, find_token_at_offset},
13}; 13};
14 14
15use crate::{ 15use crate::{
@@ -197,9 +197,9 @@ pub fn trait_from_module(
197pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver { 197pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> Resolver {
198 let file_id = position.file_id; 198 let file_id = position.file_id;
199 let file = db.parse(file_id); 199 let file = db.parse(file_id);
200 find_leaf_at_offset(file.syntax(), position.offset) 200 find_token_at_offset(file.syntax(), position.offset)
201 .find_map(|node| { 201 .find_map(|token| {
202 node.ancestors().find_map(|node| { 202 token.parent().ancestors().find_map(|node| {
203 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() { 203 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() {
204 if let Some(func) = function_from_child_node(db, file_id, node) { 204 if let Some(func) = function_from_child_node(db, file_id, node) {
205 let scopes = func.scopes(db); 205 let scopes = func.scopes(db);
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 1e84e2d06..0b7c841df 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2282,14 +2282,12 @@ fn infer(content: &str) -> String {
2282 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end())); 2282 types.sort_by_key(|(ptr, _)| (ptr.range().start(), ptr.range().end()));
2283 for (syntax_ptr, ty) in &types { 2283 for (syntax_ptr, ty) in &types {
2284 let node = syntax_ptr.to_node(&source_file); 2284 let node = syntax_ptr.to_node(&source_file);
2285 write!( 2285 let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node) {
2286 acc, 2286 (self_param.self_kw_token().range(), "self".to_string())
2287 "{} '{}': {}\n", 2287 } else {
2288 syntax_ptr.range(), 2288 (syntax_ptr.range(), node.text().to_string().replace("\n", " "))
2289 ellipsize(node.text().to_string().replace("\n", " "), 15), 2289 };
2290 ty.display(&db) 2290 write!(acc, "{} '{}': {}\n", range, ellipsize(text, 15), ty.display(&db)).unwrap();
2291 )
2292 .unwrap();
2293 } 2291 }
2294 }; 2292 };
2295 2293