aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/ra_hir/src/db.rs9
-rw-r--r--crates/ra_hir/src/has_source.rs42
-rw-r--r--crates/ra_hir/src/semantics.rs49
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs73
-rw-r--r--crates/ra_hir/src/source_analyzer.rs22
6 files changed, 93 insertions, 108 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 859bdfb3b..27cdabea0 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -361,8 +361,8 @@ pub struct Field {
361 361
362#[derive(Debug, PartialEq, Eq)] 362#[derive(Debug, PartialEq, Eq)]
363pub enum FieldSource { 363pub enum FieldSource {
364 Named(ast::RecordFieldDef), 364 Named(ast::RecordField),
365 Pos(ast::TupleFieldDef), 365 Pos(ast::TupleField),
366} 366}
367 367
368impl Field { 368impl Field {
@@ -1002,7 +1002,7 @@ impl Local {
1002 Type::new(db, krate, def, ty) 1002 Type::new(db, krate, def, ty)
1003 } 1003 }
1004 1004
1005 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::BindPat, ast::SelfParam>> { 1005 pub fn source(self, db: &dyn HirDatabase) -> InFile<Either<ast::IdentPat, ast::SelfParam>> {
1006 let (_body, source_map) = db.body_with_source_map(self.parent.into()); 1006 let (_body, source_map) = db.body_with_source_map(self.parent.into());
1007 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm... 1007 let src = source_map.pat_syntax(self.pat_id).unwrap(); // Hmm...
1008 let root = src.file_syntax(db.upcast()); 1008 let root = src.file_syntax(db.upcast());
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index a2b9f3e35..07333c453 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -13,14 +13,7 @@ pub use hir_expand::db::{
13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery, 13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery, 14 MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
15}; 15};
16pub use hir_ty::db::{ 16pub use hir_ty::db::*;
17 AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery,
18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, InferQueryQuery,
20 InherentImplsInCrateQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
21 TraitDatumQuery, TraitImplsInCrateQuery, TraitImplsInDepsQuery, TraitSolveQuery, TyQuery,
22 ValueTyQuery,
23};
24 17
25#[test] 18#[test]
26fn hir_database_is_object_safe() { 19fn hir_database_is_object_safe() {
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs
index 4fd675039..db9228d67 100644
--- a/crates/ra_hir/src/has_source.rs
+++ b/crates/ra_hir/src/has_source.rs
@@ -57,56 +57,56 @@ impl HasSource for Field {
57 } 57 }
58} 58}
59impl HasSource for Struct { 59impl HasSource for Struct {
60 type Ast = ast::StructDef; 60 type Ast = ast::Struct;
61 fn source(self, db: &dyn HirDatabase) -> InFile<ast::StructDef> { 61 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Struct> {
62 self.id.lookup(db.upcast()).source(db.upcast()) 62 self.id.lookup(db.upcast()).source(db.upcast())
63 } 63 }
64} 64}
65impl HasSource for Union { 65impl HasSource for Union {
66 type Ast = ast::UnionDef; 66 type Ast = ast::Union;
67 fn source(self, db: &dyn HirDatabase) -> InFile<ast::UnionDef> { 67 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Union> {
68 self.id.lookup(db.upcast()).source(db.upcast()) 68 self.id.lookup(db.upcast()).source(db.upcast())
69 } 69 }
70} 70}
71impl HasSource for Enum { 71impl HasSource for Enum {
72 type Ast = ast::EnumDef; 72 type Ast = ast::Enum;
73 fn source(self, db: &dyn HirDatabase) -> InFile<ast::EnumDef> { 73 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Enum> {
74 self.id.lookup(db.upcast()).source(db.upcast()) 74 self.id.lookup(db.upcast()).source(db.upcast())
75 } 75 }
76} 76}
77impl HasSource for EnumVariant { 77impl HasSource for EnumVariant {
78 type Ast = ast::EnumVariant; 78 type Ast = ast::Variant;
79 fn source(self, db: &dyn HirDatabase) -> InFile<ast::EnumVariant> { 79 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Variant> {
80 self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone()) 80 self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone())
81 } 81 }
82} 82}
83impl HasSource for Function { 83impl HasSource for Function {
84 type Ast = ast::FnDef; 84 type Ast = ast::Fn;
85 fn source(self, db: &dyn HirDatabase) -> InFile<ast::FnDef> { 85 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> {
86 self.id.lookup(db.upcast()).source(db.upcast()) 86 self.id.lookup(db.upcast()).source(db.upcast())
87 } 87 }
88} 88}
89impl HasSource for Const { 89impl HasSource for Const {
90 type Ast = ast::ConstDef; 90 type Ast = ast::Const;
91 fn source(self, db: &dyn HirDatabase) -> InFile<ast::ConstDef> { 91 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Const> {
92 self.id.lookup(db.upcast()).source(db.upcast()) 92 self.id.lookup(db.upcast()).source(db.upcast())
93 } 93 }
94} 94}
95impl HasSource for Static { 95impl HasSource for Static {
96 type Ast = ast::StaticDef; 96 type Ast = ast::Static;
97 fn source(self, db: &dyn HirDatabase) -> InFile<ast::StaticDef> { 97 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Static> {
98 self.id.lookup(db.upcast()).source(db.upcast()) 98 self.id.lookup(db.upcast()).source(db.upcast())
99 } 99 }
100} 100}
101impl HasSource for Trait { 101impl HasSource for Trait {
102 type Ast = ast::TraitDef; 102 type Ast = ast::Trait;
103 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TraitDef> { 103 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Trait> {
104 self.id.lookup(db.upcast()).source(db.upcast()) 104 self.id.lookup(db.upcast()).source(db.upcast())
105 } 105 }
106} 106}
107impl HasSource for TypeAlias { 107impl HasSource for TypeAlias {
108 type Ast = ast::TypeAliasDef; 108 type Ast = ast::TypeAlias;
109 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TypeAliasDef> { 109 fn source(self, db: &dyn HirDatabase) -> InFile<ast::TypeAlias> {
110 self.id.lookup(db.upcast()).source(db.upcast()) 110 self.id.lookup(db.upcast()).source(db.upcast())
111 } 111 }
112} 112}
@@ -120,14 +120,14 @@ impl HasSource for MacroDef {
120 } 120 }
121} 121}
122impl HasSource for ImplDef { 122impl HasSource for ImplDef {
123 type Ast = ast::ImplDef; 123 type Ast = ast::Impl;
124 fn source(self, db: &dyn HirDatabase) -> InFile<ast::ImplDef> { 124 fn source(self, db: &dyn HirDatabase) -> InFile<ast::Impl> {
125 self.id.lookup(db.upcast()).source(db.upcast()) 125 self.id.lookup(db.upcast()).source(db.upcast())
126 } 126 }
127} 127}
128 128
129impl HasSource for TypeParam { 129impl HasSource for TypeParam {
130 type Ast = Either<ast::TraitDef, ast::TypeParam>; 130 type Ast = Either<ast::Trait, ast::TypeParam>;
131 fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> { 131 fn source(self, db: &dyn HirDatabase) -> InFile<Self::Ast> {
132 let child_source = self.id.parent.child_source(db.upcast()); 132 let child_source = self.id.parent.child_source(db.upcast());
133 child_source.map(|it| it[self.id.local_id].clone()) 133 child_source.map(|it| it[self.id.local_id].clone())
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 1436b1afe..307b336f2 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -209,11 +209,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
209 self.imp.resolve_field(field) 209 self.imp.resolve_field(field)
210 } 210 }
211 211
212 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { 212 pub fn resolve_record_field(
213 &self,
214 field: &ast::RecordExprField,
215 ) -> Option<(Field, Option<Local>)> {
213 self.imp.resolve_record_field(field) 216 self.imp.resolve_record_field(field)
214 } 217 }
215 218
216 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { 219 pub fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
217 self.imp.resolve_record_field_pat(field) 220 self.imp.resolve_record_field_pat(field)
218 } 221 }
219 222
@@ -225,7 +228,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
225 self.imp.resolve_path(path) 228 self.imp.resolve_path(path)
226 } 229 }
227 230
228 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantDef> { 231 pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef> {
229 self.imp.resolve_variant(record_lit).map(VariantDef::from) 232 self.imp.resolve_variant(record_lit).map(VariantDef::from)
230 } 233 }
231 234
@@ -233,14 +236,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
233 self.imp.lower_path(path) 236 self.imp.lower_path(path)
234 } 237 }
235 238
236 pub fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { 239 pub fn resolve_bind_pat_to_const(&self, pat: &ast::IdentPat) -> Option<ModuleDef> {
237 self.imp.resolve_bind_pat_to_const(pat) 240 self.imp.resolve_bind_pat_to_const(pat)
238 } 241 }
239 242
240 // FIXME: use this instead? 243 // FIXME: use this instead?
241 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; 244 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
242 245
243 pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { 246 pub fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
244 self.imp.record_literal_missing_fields(literal) 247 self.imp.record_literal_missing_fields(literal)
245 } 248 }
246 249
@@ -422,11 +425,11 @@ impl<'db> SemanticsImpl<'db> {
422 self.analyze(field.syntax()).resolve_field(self.db, field) 425 self.analyze(field.syntax()).resolve_field(self.db, field)
423 } 426 }
424 427
425 fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> { 428 fn resolve_record_field(&self, field: &ast::RecordExprField) -> Option<(Field, Option<Local>)> {
426 self.analyze(field.syntax()).resolve_record_field(self.db, field) 429 self.analyze(field.syntax()).resolve_record_field(self.db, field)
427 } 430 }
428 431
429 fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> { 432 fn resolve_record_field_pat(&self, field: &ast::RecordPatField) -> Option<Field> {
430 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) 433 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
431 } 434 }
432 435
@@ -440,7 +443,7 @@ impl<'db> SemanticsImpl<'db> {
440 self.analyze(path.syntax()).resolve_path(self.db, path) 443 self.analyze(path.syntax()).resolve_path(self.db, path)
441 } 444 }
442 445
443 fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 446 fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantId> {
444 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit) 447 self.analyze(record_lit.syntax()).resolve_variant(self.db, record_lit)
445 } 448 }
446 449
@@ -449,11 +452,11 @@ impl<'db> SemanticsImpl<'db> {
449 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into())) 452 Path::from_src(path.clone(), &Hygiene::new(self.db.upcast(), src.file_id.into()))
450 } 453 }
451 454
452 fn resolve_bind_pat_to_const(&self, pat: &ast::BindPat) -> Option<ModuleDef> { 455 fn resolve_bind_pat_to_const(&self, pat: &ast::IdentPat) -> Option<ModuleDef> {
453 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat) 456 self.analyze(pat.syntax()).resolve_bind_pat_to_const(self.db, pat)
454 } 457 }
455 458
456 fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { 459 fn record_literal_missing_fields(&self, literal: &ast::RecordExpr) -> Vec<(Field, Type)> {
457 self.analyze(literal.syntax()) 460 self.analyze(literal.syntax())
458 .record_literal_missing_fields(self.db, literal) 461 .record_literal_missing_fields(self.db, literal)
459 .unwrap_or_default() 462 .unwrap_or_default()
@@ -577,21 +580,21 @@ macro_rules! to_def_impls {
577 580
578to_def_impls![ 581to_def_impls![
579 (crate::Module, ast::Module, module_to_def), 582 (crate::Module, ast::Module, module_to_def),
580 (crate::Struct, ast::StructDef, struct_to_def), 583 (crate::Struct, ast::Struct, struct_to_def),
581 (crate::Enum, ast::EnumDef, enum_to_def), 584 (crate::Enum, ast::Enum, enum_to_def),
582 (crate::Union, ast::UnionDef, union_to_def), 585 (crate::Union, ast::Union, union_to_def),
583 (crate::Trait, ast::TraitDef, trait_to_def), 586 (crate::Trait, ast::Trait, trait_to_def),
584 (crate::ImplDef, ast::ImplDef, impl_to_def), 587 (crate::ImplDef, ast::Impl, impl_to_def),
585 (crate::TypeAlias, ast::TypeAliasDef, type_alias_to_def), 588 (crate::TypeAlias, ast::TypeAlias, type_alias_to_def),
586 (crate::Const, ast::ConstDef, const_to_def), 589 (crate::Const, ast::Const, const_to_def),
587 (crate::Static, ast::StaticDef, static_to_def), 590 (crate::Static, ast::Static, static_to_def),
588 (crate::Function, ast::FnDef, fn_to_def), 591 (crate::Function, ast::Fn, fn_to_def),
589 (crate::Field, ast::RecordFieldDef, record_field_to_def), 592 (crate::Field, ast::RecordField, record_field_to_def),
590 (crate::Field, ast::TupleFieldDef, tuple_field_to_def), 593 (crate::Field, ast::TupleField, tuple_field_to_def),
591 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), 594 (crate::EnumVariant, ast::Variant, enum_variant_to_def),
592 (crate::TypeParam, ast::TypeParam, type_param_to_def), 595 (crate::TypeParam, ast::TypeParam, type_param_to_def),
593 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros 596 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros
594 (crate::Local, ast::BindPat, bind_pat_to_def), 597 (crate::Local, ast::IdentPat, bind_pat_to_def),
595]; 598];
596 599
597fn find_root(node: &SyntaxNode) -> SyntaxNode { 600fn find_root(node: &SyntaxNode) -> SyntaxNode {
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 42e5a1bdb..863e8e5ff 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -65,57 +65,48 @@ impl SourceToDefCtx<'_, '_> {
65 Some(ModuleId { krate: parent_module.krate, local_id: child_id }) 65 Some(ModuleId { krate: parent_module.krate, local_id: child_id })
66 } 66 }
67 67
68 pub(super) fn trait_to_def(&mut self, src: InFile<ast::TraitDef>) -> Option<TraitId> { 68 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
69 self.to_def(src, keys::TRAIT) 69 self.to_def(src, keys::TRAIT)
70 } 70 }
71 pub(super) fn impl_to_def(&mut self, src: InFile<ast::ImplDef>) -> Option<ImplId> { 71 pub(super) fn impl_to_def(&mut self, src: InFile<ast::Impl>) -> Option<ImplId> {
72 self.to_def(src, keys::IMPL) 72 self.to_def(src, keys::IMPL)
73 } 73 }
74 pub(super) fn fn_to_def(&mut self, src: InFile<ast::FnDef>) -> Option<FunctionId> { 74 pub(super) fn fn_to_def(&mut self, src: InFile<ast::Fn>) -> Option<FunctionId> {
75 self.to_def(src, keys::FUNCTION) 75 self.to_def(src, keys::FUNCTION)
76 } 76 }
77 pub(super) fn struct_to_def(&mut self, src: InFile<ast::StructDef>) -> Option<StructId> { 77 pub(super) fn struct_to_def(&mut self, src: InFile<ast::Struct>) -> Option<StructId> {
78 self.to_def(src, keys::STRUCT) 78 self.to_def(src, keys::STRUCT)
79 } 79 }
80 pub(super) fn enum_to_def(&mut self, src: InFile<ast::EnumDef>) -> Option<EnumId> { 80 pub(super) fn enum_to_def(&mut self, src: InFile<ast::Enum>) -> Option<EnumId> {
81 self.to_def(src, keys::ENUM) 81 self.to_def(src, keys::ENUM)
82 } 82 }
83 pub(super) fn union_to_def(&mut self, src: InFile<ast::UnionDef>) -> Option<UnionId> { 83 pub(super) fn union_to_def(&mut self, src: InFile<ast::Union>) -> Option<UnionId> {
84 self.to_def(src, keys::UNION) 84 self.to_def(src, keys::UNION)
85 } 85 }
86 pub(super) fn static_to_def(&mut self, src: InFile<ast::StaticDef>) -> Option<StaticId> { 86 pub(super) fn static_to_def(&mut self, src: InFile<ast::Static>) -> Option<StaticId> {
87 self.to_def(src, keys::STATIC) 87 self.to_def(src, keys::STATIC)
88 } 88 }
89 pub(super) fn const_to_def(&mut self, src: InFile<ast::ConstDef>) -> Option<ConstId> { 89 pub(super) fn const_to_def(&mut self, src: InFile<ast::Const>) -> Option<ConstId> {
90 self.to_def(src, keys::CONST) 90 self.to_def(src, keys::CONST)
91 } 91 }
92 pub(super) fn type_alias_to_def( 92 pub(super) fn type_alias_to_def(&mut self, src: InFile<ast::TypeAlias>) -> Option<TypeAliasId> {
93 &mut self,
94 src: InFile<ast::TypeAliasDef>,
95 ) -> Option<TypeAliasId> {
96 self.to_def(src, keys::TYPE_ALIAS) 93 self.to_def(src, keys::TYPE_ALIAS)
97 } 94 }
98 pub(super) fn record_field_to_def( 95 pub(super) fn record_field_to_def(&mut self, src: InFile<ast::RecordField>) -> Option<FieldId> {
99 &mut self,
100 src: InFile<ast::RecordFieldDef>,
101 ) -> Option<FieldId> {
102 self.to_def(src, keys::RECORD_FIELD) 96 self.to_def(src, keys::RECORD_FIELD)
103 } 97 }
104 pub(super) fn tuple_field_to_def( 98 pub(super) fn tuple_field_to_def(&mut self, src: InFile<ast::TupleField>) -> Option<FieldId> {
105 &mut self,
106 src: InFile<ast::TupleFieldDef>,
107 ) -> Option<FieldId> {
108 self.to_def(src, keys::TUPLE_FIELD) 99 self.to_def(src, keys::TUPLE_FIELD)
109 } 100 }
110 pub(super) fn enum_variant_to_def( 101 pub(super) fn enum_variant_to_def(
111 &mut self, 102 &mut self,
112 src: InFile<ast::EnumVariant>, 103 src: InFile<ast::Variant>,
113 ) -> Option<EnumVariantId> { 104 ) -> Option<EnumVariantId> {
114 self.to_def(src, keys::ENUM_VARIANT) 105 self.to_def(src, keys::VARIANT)
115 } 106 }
116 pub(super) fn bind_pat_to_def( 107 pub(super) fn bind_pat_to_def(
117 &mut self, 108 &mut self,
118 src: InFile<ast::BindPat>, 109 src: InFile<ast::IdentPat>,
119 ) -> Option<(DefWithBodyId, PatId)> { 110 ) -> Option<(DefWithBodyId, PatId)> {
120 let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?; 111 let container = self.find_pat_container(src.as_ref().map(|it| it.syntax()))?;
121 let (_body, source_map) = self.db.body_with_source_map(container); 112 let (_body, source_map) = self.db.body_with_source_map(container);
@@ -163,39 +154,39 @@ impl SourceToDefCtx<'_, '_> {
163 let def = self.module_to_def(container.with_value(it))?; 154 let def = self.module_to_def(container.with_value(it))?;
164 def.into() 155 def.into()
165 }, 156 },
166 ast::TraitDef(it) => { 157 ast::Trait(it) => {
167 let def = self.trait_to_def(container.with_value(it))?; 158 let def = self.trait_to_def(container.with_value(it))?;
168 def.into() 159 def.into()
169 }, 160 },
170 ast::ImplDef(it) => { 161 ast::Impl(it) => {
171 let def = self.impl_to_def(container.with_value(it))?; 162 let def = self.impl_to_def(container.with_value(it))?;
172 def.into() 163 def.into()
173 }, 164 },
174 ast::FnDef(it) => { 165 ast::Fn(it) => {
175 let def = self.fn_to_def(container.with_value(it))?; 166 let def = self.fn_to_def(container.with_value(it))?;
176 DefWithBodyId::from(def).into() 167 DefWithBodyId::from(def).into()
177 }, 168 },
178 ast::StructDef(it) => { 169 ast::Struct(it) => {
179 let def = self.struct_to_def(container.with_value(it))?; 170 let def = self.struct_to_def(container.with_value(it))?;
180 VariantId::from(def).into() 171 VariantId::from(def).into()
181 }, 172 },
182 ast::EnumDef(it) => { 173 ast::Enum(it) => {
183 let def = self.enum_to_def(container.with_value(it))?; 174 let def = self.enum_to_def(container.with_value(it))?;
184 def.into() 175 def.into()
185 }, 176 },
186 ast::UnionDef(it) => { 177 ast::Union(it) => {
187 let def = self.union_to_def(container.with_value(it))?; 178 let def = self.union_to_def(container.with_value(it))?;
188 VariantId::from(def).into() 179 VariantId::from(def).into()
189 }, 180 },
190 ast::StaticDef(it) => { 181 ast::Static(it) => {
191 let def = self.static_to_def(container.with_value(it))?; 182 let def = self.static_to_def(container.with_value(it))?;
192 DefWithBodyId::from(def).into() 183 DefWithBodyId::from(def).into()
193 }, 184 },
194 ast::ConstDef(it) => { 185 ast::Const(it) => {
195 let def = self.const_to_def(container.with_value(it))?; 186 let def = self.const_to_def(container.with_value(it))?;
196 DefWithBodyId::from(def).into() 187 DefWithBodyId::from(def).into()
197 }, 188 },
198 ast::TypeAliasDef(it) => { 189 ast::TypeAlias(it) => {
199 let def = self.type_alias_to_def(container.with_value(it))?; 190 let def = self.type_alias_to_def(container.with_value(it))?;
200 def.into() 191 def.into()
201 }, 192 },
@@ -213,12 +204,12 @@ impl SourceToDefCtx<'_, '_> {
213 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { 204 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
214 let res: GenericDefId = match_ast! { 205 let res: GenericDefId = match_ast! {
215 match (container.value) { 206 match (container.value) {
216 ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), 207 ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
217 ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), 208 ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(),
218 ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), 209 ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(),
219 ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), 210 ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(),
220 ast::TypeAliasDef(it) => self.type_alias_to_def(container.with_value(it))?.into(), 211 ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(),
221 ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), 212 ast::Impl(it) => self.impl_to_def(container.with_value(it))?.into(),
222 _ => continue, 213 _ => continue,
223 } 214 }
224 }; 215 };
@@ -231,9 +222,9 @@ impl SourceToDefCtx<'_, '_> {
231 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { 222 for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
232 let res: DefWithBodyId = match_ast! { 223 let res: DefWithBodyId = match_ast! {
233 match (container.value) { 224 match (container.value) {
234 ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), 225 ast::Const(it) => self.const_to_def(container.with_value(it))?.into(),
235 ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), 226 ast::Static(it) => self.static_to_def(container.with_value(it))?.into(),
236 ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), 227 ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(),
237 _ => continue, 228 _ => continue,
238 } 229 }
239 }; 230 };
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 86a47a9e5..d0cb62ef0 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -159,7 +159,7 @@ impl SourceAnalyzer {
159 pub(crate) fn resolve_record_field( 159 pub(crate) fn resolve_record_field(
160 &self, 160 &self,
161 db: &dyn HirDatabase, 161 db: &dyn HirDatabase,
162 field: &ast::RecordField, 162 field: &ast::RecordExprField,
163 ) -> Option<(Field, Option<Local>)> { 163 ) -> Option<(Field, Option<Local>)> {
164 let expr = field.expr()?; 164 let expr = field.expr()?;
165 let expr_id = self.expr_id(db, &expr)?; 165 let expr_id = self.expr_id(db, &expr)?;
@@ -182,7 +182,7 @@ impl SourceAnalyzer {
182 pub(crate) fn resolve_record_field_pat( 182 pub(crate) fn resolve_record_field_pat(
183 &self, 183 &self,
184 _db: &dyn HirDatabase, 184 _db: &dyn HirDatabase,
185 field: &ast::RecordFieldPat, 185 field: &ast::RecordPatField,
186 ) -> Option<Field> { 186 ) -> Option<Field> {
187 let pat_id = self.pat_id(&field.pat()?)?; 187 let pat_id = self.pat_id(&field.pat()?)?;
188 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; 188 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?;
@@ -202,7 +202,7 @@ impl SourceAnalyzer {
202 pub(crate) fn resolve_bind_pat_to_const( 202 pub(crate) fn resolve_bind_pat_to_const(
203 &self, 203 &self,
204 db: &dyn HirDatabase, 204 db: &dyn HirDatabase,
205 pat: &ast::BindPat, 205 pat: &ast::IdentPat,
206 ) -> Option<ModuleDef> { 206 ) -> Option<ModuleDef> {
207 let pat_id = self.pat_id(&pat.clone().into())?; 207 let pat_id = self.pat_id(&pat.clone().into())?;
208 let body = self.body.as_ref()?; 208 let body = self.body.as_ref()?;
@@ -246,7 +246,7 @@ impl SourceAnalyzer {
246 } 246 }
247 } 247 }
248 248
249 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordLit::cast) { 249 if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordExpr::cast) {
250 let expr_id = self.expr_id(db, &rec_lit.into())?; 250 let expr_id = self.expr_id(db, &rec_lit.into())?;
251 if let Some(VariantId::EnumVariantId(variant)) = 251 if let Some(VariantId::EnumVariantId(variant)) =
252 self.infer.as_ref()?.variant_resolution_for_expr(expr_id) 252 self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
@@ -284,7 +284,7 @@ impl SourceAnalyzer {
284 pub(crate) fn record_literal_missing_fields( 284 pub(crate) fn record_literal_missing_fields(
285 &self, 285 &self,
286 db: &dyn HirDatabase, 286 db: &dyn HirDatabase,
287 literal: &ast::RecordLit, 287 literal: &ast::RecordExpr,
288 ) -> Option<Vec<(Field, Type)>> { 288 ) -> Option<Vec<(Field, Type)>> {
289 let krate = self.resolver.krate()?; 289 let krate = self.resolver.krate()?;
290 let body = self.body.as_ref()?; 290 let body = self.body.as_ref()?;
@@ -358,7 +358,7 @@ impl SourceAnalyzer {
358 pub(crate) fn resolve_variant( 358 pub(crate) fn resolve_variant(
359 &self, 359 &self,
360 db: &dyn HirDatabase, 360 db: &dyn HirDatabase,
361 record_lit: ast::RecordLit, 361 record_lit: ast::RecordExpr,
362 ) -> Option<VariantId> { 362 ) -> Option<VariantId> {
363 let infer = self.infer.as_ref()?; 363 let infer = self.infer.as_ref()?;
364 let expr_id = self.expr_id(db, &record_lit.into())?; 364 let expr_id = self.expr_id(db, &record_lit.into())?;
@@ -405,8 +405,7 @@ fn scope_for_offset(
405 ) 405 )
406 }) 406 })
407 .map(|(expr_range, scope)| { 407 .map(|(expr_range, scope)| {
408 adjust(db, scopes, source_map, expr_range, offset.file_id, offset.value) 408 adjust(db, scopes, source_map, expr_range, offset).unwrap_or(*scope)
409 .unwrap_or(*scope)
410 }) 409 })
411} 410}
412 411
@@ -417,8 +416,7 @@ fn adjust(
417 scopes: &ExprScopes, 416 scopes: &ExprScopes,
418 source_map: &BodySourceMap, 417 source_map: &BodySourceMap,
419 expr_range: TextRange, 418 expr_range: TextRange,
420 file_id: HirFileId, 419 offset: InFile<TextSize>,
421 offset: TextSize,
422) -> Option<ScopeId> { 420) -> Option<ScopeId> {
423 let child_scopes = scopes 421 let child_scopes = scopes
424 .scope_by_expr() 422 .scope_by_expr()
@@ -426,7 +424,7 @@ fn adjust(
426 .filter_map(|(id, scope)| { 424 .filter_map(|(id, scope)| {
427 let source = source_map.expr_syntax(*id).ok()?; 425 let source = source_map.expr_syntax(*id).ok()?;
428 // FIXME: correctly handle macro expansion 426 // FIXME: correctly handle macro expansion
429 if source.file_id != file_id { 427 if source.file_id != offset.file_id {
430 return None; 428 return None;
431 } 429 }
432 let root = source.file_syntax(db.upcast()); 430 let root = source.file_syntax(db.upcast());
@@ -434,7 +432,7 @@ fn adjust(
434 Some((node.syntax().text_range(), scope)) 432 Some((node.syntax().text_range(), scope))
435 }) 433 })
436 .filter(|&(range, _)| { 434 .filter(|&(range, _)| {
437 range.start() <= offset && expr_range.contains_range(range) && range != expr_range 435 range.start() <= offset.value && expr_range.contains_range(range) && range != expr_range
438 }); 436 });
439 437
440 child_scopes 438 child_scopes