aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs34
-rw-r--r--crates/ra_hir/src/from_id.rs22
-rw-r--r--crates/ra_hir/src/has_source.rs6
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/semantics.rs27
-rw-r--r--crates/ra_hir/src/semantics/source_to_def.rs8
-rw-r--r--crates/ra_hir/src/source_analyzer.rs22
-rw-r--r--crates/ra_hir_def/src/adt.rs22
-rw-r--r--crates/ra_hir_def/src/attr.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs6
-rw-r--r--crates/ra_hir_def/src/docs.rs2
-rw-r--r--crates/ra_hir_def/src/keys.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs10
-rw-r--r--crates/ra_hir_ty/src/db.rs4
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs16
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs8
-rw-r--r--crates/ra_hir_ty/src/infer/pat.rs4
-rw-r--r--crates/ra_hir_ty/src/lower.rs6
-rw-r--r--crates/ra_ide/src/completion/presentation.rs7
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide/src/hover.rs4
-rw-r--r--crates/ra_ide/src/references.rs2
-rw-r--r--crates/ra_ide/src/references/rename.rs4
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs2
-rw-r--r--crates/ra_ide_db/src/defs.rs22
-rw-r--r--crates/ra_ide_db/src/search.rs12
27 files changed, 132 insertions, 148 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 43f932e20..3f645a1dd 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -13,8 +13,8 @@ use hir_def::{
13 resolver::{HasResolver, Resolver}, 13 resolver::{HasResolver, Resolver},
14 type_ref::{Mutability, TypeRef}, 14 type_ref::{Mutability, TypeRef},
15 AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, 15 AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule,
16 ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, 16 ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId,
17 StructId, TraitId, TypeAliasId, TypeParamId, UnionId, 17 TraitId, TypeAliasId, TypeParamId, UnionId,
18}; 18};
19use hir_expand::{ 19use hir_expand::{
20 diagnostics::DiagnosticSink, 20 diagnostics::DiagnosticSink,
@@ -294,9 +294,9 @@ impl Module {
294} 294}
295 295
296#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 296#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
297pub struct StructField { 297pub struct Field {
298 pub(crate) parent: VariantDef, 298 pub(crate) parent: VariantDef,
299 pub(crate) id: LocalStructFieldId, 299 pub(crate) id: LocalFieldId,
300} 300}
301 301
302#[derive(Debug, PartialEq, Eq)] 302#[derive(Debug, PartialEq, Eq)]
@@ -305,7 +305,7 @@ pub enum FieldSource {
305 Pos(ast::TupleFieldDef), 305 Pos(ast::TupleFieldDef),
306} 306}
307 307
308impl StructField { 308impl Field {
309 pub fn name(&self, db: &dyn HirDatabase) -> Name { 309 pub fn name(&self, db: &dyn HirDatabase) -> Name {
310 self.parent.variant_data(db).fields()[self.id].name.clone() 310 self.parent.variant_data(db).fields()[self.id].name.clone()
311 } 311 }
@@ -331,7 +331,7 @@ impl StructField {
331 } 331 }
332} 332}
333 333
334impl HasVisibility for StructField { 334impl HasVisibility for Field {
335 fn visibility(&self, db: &dyn HirDatabase) -> Visibility { 335 fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
336 let variant_data = self.parent.variant_data(db); 336 let variant_data = self.parent.variant_data(db);
337 let visibility = &variant_data.fields()[self.id].visibility; 337 let visibility = &variant_data.fields()[self.id].visibility;
@@ -358,12 +358,12 @@ impl Struct {
358 db.struct_data(self.id).name.clone() 358 db.struct_data(self.id).name.clone()
359 } 359 }
360 360
361 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 361 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
362 db.struct_data(self.id) 362 db.struct_data(self.id)
363 .variant_data 363 .variant_data
364 .fields() 364 .fields()
365 .iter() 365 .iter()
366 .map(|(id, _)| StructField { parent: self.into(), id }) 366 .map(|(id, _)| Field { parent: self.into(), id })
367 .collect() 367 .collect()
368 } 368 }
369 369
@@ -394,12 +394,12 @@ impl Union {
394 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 394 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id)
395 } 395 }
396 396
397 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 397 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
398 db.union_data(self.id) 398 db.union_data(self.id)
399 .variant_data 399 .variant_data
400 .fields() 400 .fields()
401 .iter() 401 .iter()
402 .map(|(id, _)| StructField { parent: self.into(), id }) 402 .map(|(id, _)| Field { parent: self.into(), id })
403 .collect() 403 .collect()
404 } 404 }
405 405
@@ -457,11 +457,11 @@ impl EnumVariant {
457 db.enum_data(self.parent.id).variants[self.id].name.clone() 457 db.enum_data(self.parent.id).variants[self.id].name.clone()
458 } 458 }
459 459
460 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 460 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
461 self.variant_data(db) 461 self.variant_data(db)
462 .fields() 462 .fields()
463 .iter() 463 .iter()
464 .map(|(id, _)| StructField { parent: self.into(), id }) 464 .map(|(id, _)| Field { parent: self.into(), id })
465 .collect() 465 .collect()
466 } 466 }
467 467
@@ -527,7 +527,7 @@ pub enum VariantDef {
527impl_froms!(VariantDef: Struct, Union, EnumVariant); 527impl_froms!(VariantDef: Struct, Union, EnumVariant);
528 528
529impl VariantDef { 529impl VariantDef {
530 pub fn fields(self, db: &dyn HirDatabase) -> Vec<StructField> { 530 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
531 match self { 531 match self {
532 VariantDef::Struct(it) => it.fields(db), 532 VariantDef::Struct(it) => it.fields(db),
533 VariantDef::Union(it) => it.fields(db), 533 VariantDef::Union(it) => it.fields(db),
@@ -1148,7 +1148,7 @@ impl Type {
1148 } 1148 }
1149 } 1149 }
1150 1150
1151 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(StructField, Type)> { 1151 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
1152 if let Ty::Apply(a_ty) = &self.ty.value { 1152 if let Ty::Apply(a_ty) = &self.ty.value {
1153 if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { 1153 if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor {
1154 let var_def = s.into(); 1154 let var_def = s.into();
@@ -1156,7 +1156,7 @@ impl Type {
1156 .field_types(var_def) 1156 .field_types(var_def)
1157 .iter() 1157 .iter()
1158 .map(|(local_id, ty)| { 1158 .map(|(local_id, ty)| {
1159 let def = StructField { parent: var_def.into(), id: local_id }; 1159 let def = Field { parent: var_def.into(), id: local_id };
1160 let ty = ty.clone().subst(&a_ty.parameters); 1160 let ty = ty.clone().subst(&a_ty.parameters);
1161 (def, self.derived(ty)) 1161 (def, self.derived(ty))
1162 }) 1162 })
@@ -1352,7 +1352,7 @@ impl ScopeDef {
1352#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 1352#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1353pub enum AttrDef { 1353pub enum AttrDef {
1354 Module(Module), 1354 Module(Module),
1355 StructField(StructField), 1355 Field(Field),
1356 Adt(Adt), 1356 Adt(Adt),
1357 Function(Function), 1357 Function(Function),
1358 EnumVariant(EnumVariant), 1358 EnumVariant(EnumVariant),
@@ -1365,7 +1365,7 @@ pub enum AttrDef {
1365 1365
1366impl_froms!( 1366impl_froms!(
1367 AttrDef: Module, 1367 AttrDef: Module,
1368 StructField, 1368 Field,
1369 Adt(Struct, Enum, Union), 1369 Adt(Struct, Enum, Union),
1370 EnumVariant, 1370 EnumVariant,
1371 Static, 1371 Static,
diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs
index 62fb52e72..679ae8121 100644
--- a/crates/ra_hir/src/from_id.rs
+++ b/crates/ra_hir/src/from_id.rs
@@ -4,13 +4,13 @@
4//! are splitting the hir. 4//! are splitting the hir.
5 5
6use hir_def::{ 6use hir_def::{
7 expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, 7 expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, FieldId,
8 ModuleDefId, StructFieldId, VariantId, 8 GenericDefId, ModuleDefId, VariantId,
9}; 9};
10 10
11use crate::{ 11use crate::{
12 code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, 12 code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, Field, GenericDef,
13 MacroDef, ModuleDef, StructField, VariantDef, 13 Local, MacroDef, ModuleDef, VariantDef,
14}; 14};
15 15
16macro_rules! from_id { 16macro_rules! from_id {
@@ -184,15 +184,15 @@ impl From<VariantDef> for VariantId {
184 } 184 }
185} 185}
186 186
187impl From<StructField> for StructFieldId { 187impl From<Field> for FieldId {
188 fn from(def: StructField) -> Self { 188 fn from(def: Field) -> Self {
189 StructFieldId { parent: def.parent.into(), local_id: def.id } 189 FieldId { parent: def.parent.into(), local_id: def.id }
190 } 190 }
191} 191}
192 192
193impl From<StructFieldId> for StructField { 193impl From<FieldId> for Field {
194 fn from(def: StructFieldId) -> Self { 194 fn from(def: FieldId) -> Self {
195 StructField { parent: def.parent.into(), id: def.local_id } 195 Field { parent: def.parent.into(), id: def.local_id }
196 } 196 }
197} 197}
198 198
@@ -200,7 +200,7 @@ impl From<AttrDef> for AttrDefId {
200 fn from(def: AttrDef) -> Self { 200 fn from(def: AttrDef) -> Self {
201 match def { 201 match def {
202 AttrDef::Module(it) => AttrDefId::ModuleId(it.id), 202 AttrDef::Module(it) => AttrDefId::ModuleId(it.id),
203 AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()), 203 AttrDef::Field(it) => AttrDefId::FieldId(it.into()),
204 AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), 204 AttrDef::Adt(it) => AttrDefId::AdtId(it.into()),
205 AttrDef::Function(it) => AttrDefId::FunctionId(it.id), 205 AttrDef::Function(it) => AttrDefId::FunctionId(it.id),
206 AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()), 206 AttrDef::EnumVariant(it) => AttrDefId::EnumVariantId(it.into()),
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs
index 129764e0a..63b8fd369 100644
--- a/crates/ra_hir/src/has_source.rs
+++ b/crates/ra_hir/src/has_source.rs
@@ -9,8 +9,8 @@ use hir_def::{
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
12 db::HirDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplDef, MacroDef, Module, 12 db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef,
13 Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, 13 Module, Static, Struct, Trait, TypeAlias, TypeParam, Union,
14}; 14};
15 15
16pub use hir_expand::InFile; 16pub use hir_expand::InFile;
@@ -37,7 +37,7 @@ impl Module {
37 } 37 }
38} 38}
39 39
40impl HasSource for StructField { 40impl HasSource for Field {
41 type Ast = FieldSource; 41 type Ast = FieldSource;
42 fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> { 42 fn source(self, db: &dyn HirDatabase) -> InFile<FieldSource> {
43 let var = VariantId::from(self.parent); 43 let var = VariantId::from(self.parent);
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 5af7e5d6d..312ef3814 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -52,9 +52,9 @@ mod has_source;
52pub use crate::{ 52pub use crate::{
53 code_model::{ 53 code_model::{
54 Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, 54 Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency,
55 DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, 55 DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs,
56 HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, 56 HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct,
57 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, 57 Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility,
58 }, 58 },
59 has_source::HasSource, 59 has_source::HasSource,
60 semantics::{original_range, PathResolution, Semantics, SemanticsScope}, 60 semantics::{original_range, PathResolution, Semantics, SemanticsScope},
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index e09cf3185..86bfb416c 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -23,8 +23,8 @@ use crate::{
23 diagnostics::Diagnostic, 23 diagnostics::Diagnostic,
24 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 24 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
25 source_analyzer::{resolve_hir_path, SourceAnalyzer}, 25 source_analyzer::{resolve_hir_path, SourceAnalyzer},
26 AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name, 26 AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef,
27 Origin, Path, ScopeDef, StructField, Trait, Type, TypeParam, 27 Name, Origin, Path, ScopeDef, Trait, Type, TypeParam,
28}; 28};
29 29
30#[derive(Debug, Clone, PartialEq, Eq)] 30#[derive(Debug, Clone, PartialEq, Eq)]
@@ -184,18 +184,15 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
184 self.analyze(call.syntax()).resolve_method_call(self.db, call) 184 self.analyze(call.syntax()).resolve_method_call(self.db, call)
185 } 185 }
186 186
187 pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<StructField> { 187 pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option<Field> {
188 self.analyze(field.syntax()).resolve_field(self.db, field) 188 self.analyze(field.syntax()).resolve_field(self.db, field)
189 } 189 }
190 190
191 pub fn resolve_record_field( 191 pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option<Local>)> {
192 &self,
193 field: &ast::RecordField,
194 ) -> Option<(StructField, Option<Local>)> {
195 self.analyze(field.syntax()).resolve_record_field(self.db, field) 192 self.analyze(field.syntax()).resolve_record_field(self.db, field)
196 } 193 }
197 194
198 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<StructField> { 195 pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option<Field> {
199 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) 196 self.analyze(field.syntax()).resolve_record_field_pat(self.db, field)
200 } 197 }
201 198
@@ -216,19 +213,13 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
216 // FIXME: use this instead? 213 // FIXME: use this instead?
217 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>; 214 // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option<???>;
218 215
219 pub fn record_literal_missing_fields( 216 pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> {
220 &self,
221 literal: &ast::RecordLit,
222 ) -> Vec<(StructField, Type)> {
223 self.analyze(literal.syntax()) 217 self.analyze(literal.syntax())
224 .record_literal_missing_fields(self.db, literal) 218 .record_literal_missing_fields(self.db, literal)
225 .unwrap_or_default() 219 .unwrap_or_default()
226 } 220 }
227 221
228 pub fn record_pattern_missing_fields( 222 pub fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> {
229 &self,
230 pattern: &ast::RecordPat,
231 ) -> Vec<(StructField, Type)> {
232 self.analyze(pattern.syntax()) 223 self.analyze(pattern.syntax())
233 .record_pattern_missing_fields(self.db, pattern) 224 .record_pattern_missing_fields(self.db, pattern)
234 .unwrap_or_default() 225 .unwrap_or_default()
@@ -359,8 +350,8 @@ to_def_impls![
359 (crate::Const, ast::ConstDef, const_to_def), 350 (crate::Const, ast::ConstDef, const_to_def),
360 (crate::Static, ast::StaticDef, static_to_def), 351 (crate::Static, ast::StaticDef, static_to_def),
361 (crate::Function, ast::FnDef, fn_to_def), 352 (crate::Function, ast::FnDef, fn_to_def),
362 (crate::StructField, ast::RecordFieldDef, record_field_to_def), 353 (crate::Field, ast::RecordFieldDef, record_field_to_def),
363 (crate::StructField, ast::TupleFieldDef, tuple_field_to_def), 354 (crate::Field, ast::TupleFieldDef, tuple_field_to_def),
364 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), 355 (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def),
365 (crate::TypeParam, ast::TypeParam, type_param_to_def), 356 (crate::TypeParam, ast::TypeParam, type_param_to_def),
366 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros 357 (crate::MacroDef, ast::MacroCall, macro_call_to_def), // this one is dubious, not all calls are macros
diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs
index 66724919b..6f3b5b2da 100644
--- a/crates/ra_hir/src/semantics/source_to_def.rs
+++ b/crates/ra_hir/src/semantics/source_to_def.rs
@@ -5,8 +5,8 @@ use hir_def::{
5 dyn_map::DynMap, 5 dyn_map::DynMap,
6 expr::PatId, 6 expr::PatId,
7 keys::{self, Key}, 7 keys::{self, Key},
8 ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, 8 ConstId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId, GenericDefId, ImplId,
9 StaticId, StructFieldId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, 9 ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
10}; 10};
11use hir_expand::{name::AsName, AstId, MacroDefKind}; 11use hir_expand::{name::AsName, AstId, MacroDefKind};
12use ra_db::FileId; 12use ra_db::FileId;
@@ -97,13 +97,13 @@ impl SourceToDefCtx<'_, '_> {
97 pub(super) fn record_field_to_def( 97 pub(super) fn record_field_to_def(
98 &mut self, 98 &mut self,
99 src: InFile<ast::RecordFieldDef>, 99 src: InFile<ast::RecordFieldDef>,
100 ) -> Option<StructFieldId> { 100 ) -> Option<FieldId> {
101 self.to_def(src, keys::RECORD_FIELD) 101 self.to_def(src, keys::RECORD_FIELD)
102 } 102 }
103 pub(super) fn tuple_field_to_def( 103 pub(super) fn tuple_field_to_def(
104 &mut self, 104 &mut self,
105 src: InFile<ast::TupleFieldDef>, 105 src: InFile<ast::TupleFieldDef>,
106 ) -> Option<StructFieldId> { 106 ) -> Option<FieldId> {
107 self.to_def(src, keys::TUPLE_FIELD) 107 self.to_def(src, keys::TUPLE_FIELD)
108 } 108 }
109 pub(super) fn enum_variant_to_def( 109 pub(super) fn enum_variant_to_def(
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 59a3a17d2..74d64c97d 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -14,7 +14,7 @@ use hir_def::{
14 }, 14 },
15 expr::{ExprId, Pat, PatId}, 15 expr::{ExprId, Pat, PatId},
16 resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, 16 resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs},
17 AsMacroCall, DefWithBodyId, LocalStructFieldId, StructFieldId, VariantId, 17 AsMacroCall, DefWithBodyId, FieldId, LocalFieldId, VariantId,
18}; 18};
19use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; 19use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile};
20use hir_ty::{ 20use hir_ty::{
@@ -27,8 +27,8 @@ use ra_syntax::{
27}; 27};
28 28
29use crate::{ 29use crate::{
30 db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Function, Local, MacroDef, 30 db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local,
31 ModPath, ModuleDef, Path, PathKind, Static, Struct, StructField, Trait, Type, TypeAlias, 31 MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias,
32 TypeParam, 32 TypeParam,
33}; 33};
34use ra_db::CrateId; 34use ra_db::CrateId;
@@ -140,7 +140,7 @@ impl SourceAnalyzer {
140 &self, 140 &self,
141 db: &dyn HirDatabase, 141 db: &dyn HirDatabase,
142 field: &ast::FieldExpr, 142 field: &ast::FieldExpr,
143 ) -> Option<StructField> { 143 ) -> Option<Field> {
144 let expr_id = self.expr_id(db, &field.clone().into())?; 144 let expr_id = self.expr_id(db, &field.clone().into())?;
145 self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) 145 self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into())
146 } 146 }
@@ -149,7 +149,7 @@ impl SourceAnalyzer {
149 &self, 149 &self,
150 db: &dyn HirDatabase, 150 db: &dyn HirDatabase,
151 field: &ast::RecordField, 151 field: &ast::RecordField,
152 ) -> Option<(StructField, Option<Local>)> { 152 ) -> Option<(Field, Option<Local>)> {
153 let expr = field.expr()?; 153 let expr = field.expr()?;
154 let expr_id = self.expr_id(db, &expr)?; 154 let expr_id = self.expr_id(db, &expr)?;
155 let local = if field.name_ref().is_some() { 155 let local = if field.name_ref().is_some() {
@@ -172,7 +172,7 @@ impl SourceAnalyzer {
172 &self, 172 &self,
173 _db: &dyn HirDatabase, 173 _db: &dyn HirDatabase,
174 field: &ast::RecordFieldPat, 174 field: &ast::RecordFieldPat,
175 ) -> Option<StructField> { 175 ) -> Option<Field> {
176 let pat_id = self.pat_id(&field.pat()?)?; 176 let pat_id = self.pat_id(&field.pat()?)?;
177 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; 177 let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?;
178 Some(struct_field.into()) 178 Some(struct_field.into())
@@ -232,7 +232,7 @@ impl SourceAnalyzer {
232 &self, 232 &self,
233 db: &dyn HirDatabase, 233 db: &dyn HirDatabase,
234 literal: &ast::RecordLit, 234 literal: &ast::RecordLit,
235 ) -> Option<Vec<(StructField, Type)>> { 235 ) -> Option<Vec<(Field, Type)>> {
236 let krate = self.resolver.krate()?; 236 let krate = self.resolver.krate()?;
237 let body = self.body.as_ref()?; 237 let body = self.body.as_ref()?;
238 let infer = self.infer.as_ref()?; 238 let infer = self.infer.as_ref()?;
@@ -253,7 +253,7 @@ impl SourceAnalyzer {
253 &self, 253 &self,
254 db: &dyn HirDatabase, 254 db: &dyn HirDatabase,
255 pattern: &ast::RecordPat, 255 pattern: &ast::RecordPat,
256 ) -> Option<Vec<(StructField, Type)>> { 256 ) -> Option<Vec<(Field, Type)>> {
257 let krate = self.resolver.krate()?; 257 let krate = self.resolver.krate()?;
258 let body = self.body.as_ref()?; 258 let body = self.body.as_ref()?;
259 let infer = self.infer.as_ref()?; 259 let infer = self.infer.as_ref()?;
@@ -276,14 +276,14 @@ impl SourceAnalyzer {
276 krate: CrateId, 276 krate: CrateId,
277 substs: &Substs, 277 substs: &Substs,
278 variant: VariantId, 278 variant: VariantId,
279 missing_fields: Vec<LocalStructFieldId>, 279 missing_fields: Vec<LocalFieldId>,
280 ) -> Vec<(StructField, Type)> { 280 ) -> Vec<(Field, Type)> {
281 let field_types = db.field_types(variant); 281 let field_types = db.field_types(variant);
282 282
283 missing_fields 283 missing_fields
284 .into_iter() 284 .into_iter()
285 .map(|local_id| { 285 .map(|local_id| {
286 let field = StructFieldId { parent: variant, local_id }; 286 let field = FieldId { parent: variant, local_id };
287 let ty = field_types[local_id].clone().subst(substs); 287 let ty = field_types[local_id].clone().subst(substs);
288 (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) 288 (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
289 }) 289 })
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 7c0d93691..753becc3d 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -14,7 +14,7 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner};
14use crate::{ 14use crate::{
15 body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, 15 body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace,
16 type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, 16 type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId,
17 LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, 17 LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId,
18}; 18};
19 19
20/// Note that we use `StructData` for unions as well! 20/// Note that we use `StructData` for unions as well!
@@ -38,14 +38,14 @@ pub struct EnumVariantData {
38 38
39#[derive(Debug, Clone, PartialEq, Eq)] 39#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum VariantData { 40pub enum VariantData {
41 Record(Arena<StructFieldData>), 41 Record(Arena<FieldData>),
42 Tuple(Arena<StructFieldData>), 42 Tuple(Arena<FieldData>),
43 Unit, 43 Unit,
44} 44}
45 45
46/// A single field of an enum variant or struct 46/// A single field of an enum variant or struct
47#[derive(Debug, Clone, PartialEq, Eq)] 47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct StructFieldData { 48pub struct FieldData {
49 pub name: Name, 49 pub name: Name,
50 pub type_ref: TypeRef, 50 pub type_ref: TypeRef,
51 pub visibility: RawVisibility, 51 pub visibility: RawVisibility,
@@ -133,15 +133,15 @@ impl VariantData {
133 } 133 }
134 } 134 }
135 135
136 pub fn fields(&self) -> &Arena<StructFieldData> { 136 pub fn fields(&self) -> &Arena<FieldData> {
137 const EMPTY: &Arena<StructFieldData> = &Arena::new(); 137 const EMPTY: &Arena<FieldData> = &Arena::new();
138 match &self { 138 match &self {
139 VariantData::Record(fields) | VariantData::Tuple(fields) => fields, 139 VariantData::Record(fields) | VariantData::Tuple(fields) => fields,
140 _ => EMPTY, 140 _ => EMPTY,
141 } 141 }
142 } 142 }
143 143
144 pub fn field(&self, name: &Name) -> Option<LocalStructFieldId> { 144 pub fn field(&self, name: &Name) -> Option<LocalFieldId> {
145 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None }) 145 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None })
146 } 146 }
147 147
@@ -155,7 +155,7 @@ impl VariantData {
155} 155}
156 156
157impl HasChildSource for VariantId { 157impl HasChildSource for VariantId {
158 type ChildId = LocalStructFieldId; 158 type ChildId = LocalFieldId;
159 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 159 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
160 160
161 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 161 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
@@ -195,7 +195,7 @@ pub enum StructKind {
195fn lower_struct( 195fn lower_struct(
196 db: &dyn DefDatabase, 196 db: &dyn DefDatabase,
197 expander: &mut CfgExpander, 197 expander: &mut CfgExpander,
198 trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, 198 trace: &mut Trace<FieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>,
199 ast: &InFile<ast::StructKind>, 199 ast: &InFile<ast::StructKind>,
200) -> StructKind { 200) -> StructKind {
201 match &ast.value { 201 match &ast.value {
@@ -208,7 +208,7 @@ fn lower_struct(
208 208
209 trace.alloc( 209 trace.alloc(
210 || Either::Left(fd.clone()), 210 || Either::Left(fd.clone()),
211 || StructFieldData { 211 || FieldData {
212 name: Name::new_tuple_field(i), 212 name: Name::new_tuple_field(i),
213 type_ref: TypeRef::from_ast_opt(fd.type_ref()), 213 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
214 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 214 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
@@ -226,7 +226,7 @@ fn lower_struct(
226 226
227 trace.alloc( 227 trace.alloc(
228 || Either::Right(fd.clone()), 228 || Either::Right(fd.clone()),
229 || StructFieldData { 229 || FieldData {
230 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 230 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
231 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), 231 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
232 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 232 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 2f2e3e5ba..714a66b02 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -43,7 +43,7 @@ impl Attrs {
43 }; 43 };
44 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 44 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
45 } 45 }
46 AttrDefId::StructFieldId(it) => { 46 AttrDefId::FieldId(it) => {
47 let src = it.parent.child_source(db); 47 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 48 match &src.value[it.local_id] {
49 Either::Left(_tuple) => Attrs::default(), 49 Either::Left(_tuple) => Attrs::default(),
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index 7009f21d1..a885ec96d 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -12,8 +12,8 @@ use crate::{
12 item_scope::ItemScope, 12 item_scope::ItemScope,
13 keys, 13 keys,
14 src::{HasChildSource, HasSource}, 14 src::{HasChildSource, HasSource},
15 AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, ImplId, Lookup, ModuleDefId, 15 AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, ModuleDefId,
16 ModuleId, StructFieldId, TraitId, VariantId, 16 ModuleId, TraitId, VariantId,
17}; 17};
18 18
19pub trait ChildBySource { 19pub trait ChildBySource {
@@ -140,7 +140,7 @@ impl ChildBySource for VariantId {
140 let arena_map = self.child_source(db); 140 let arena_map = self.child_source(db);
141 let arena_map = arena_map.as_ref(); 141 let arena_map = arena_map.as_ref();
142 for (local_id, source) in arena_map.value.iter() { 142 for (local_id, source) in arena_map.value.iter() {
143 let id = StructFieldId { parent: *self, local_id }; 143 let id = FieldId { parent: *self, local_id };
144 match source { 144 match source {
145 Either::Left(source) => { 145 Either::Left(source) => {
146 res[keys::TUPLE_FIELD].insert(arena_map.with_value(source.clone()), id) 146 res[keys::TUPLE_FIELD].insert(arena_map.with_value(source.clone()), id)
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 0539a77d4..b221ae1ce 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -43,7 +43,7 @@ impl Documentation {
43 let src = def_map[module.local_id].declaration_source(db)?; 43 let src = def_map[module.local_id].declaration_source(db)?;
44 docs_from_ast(&src.value) 44 docs_from_ast(&src.value)
45 } 45 }
46 AttrDefId::StructFieldId(it) => { 46 AttrDefId::FieldId(it) => {
47 let src = it.parent.child_source(db); 47 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 48 match &src.value[it.local_id] {
49 Either::Left(_tuple) => None, 49 Either::Left(_tuple) => None,
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index 8cd70eb9a..a7349a21d 100644
--- a/crates/ra_hir_def/src/keys.rs
+++ b/crates/ra_hir_def/src/keys.rs
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
8 8
9use crate::{ 9use crate::{
10 dyn_map::{DynMap, Policy}, 10 dyn_map::{DynMap, Policy},
11 ConstId, EnumId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, 11 ConstId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, StaticId, StructId, TraitId,
12 TypeAliasId, TypeParamId, UnionId, 12 TypeAliasId, TypeParamId, UnionId,
13}; 13};
14 14
@@ -25,8 +25,8 @@ pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();
25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new(); 25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new();
26 26
27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); 27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
28pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 28pub const TUPLE_FIELD: Key<ast::TupleFieldDef, FieldId> = Key::new();
29pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); 29pub const RECORD_FIELD: Key<ast::RecordFieldDef, FieldId> = Key::new();
30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); 30pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
31 31
32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new(); 32pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new();
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 2d27bbdf8..518772e8a 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -133,12 +133,12 @@ pub struct EnumVariantId {
133pub type LocalEnumVariantId = Idx<adt::EnumVariantData>; 133pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
134 134
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
136pub struct StructFieldId { 136pub struct FieldId {
137 pub parent: VariantId, 137 pub parent: VariantId,
138 pub local_id: LocalStructFieldId, 138 pub local_id: LocalFieldId,
139} 139}
140 140
141pub type LocalStructFieldId = Idx<adt::StructFieldData>; 141pub type LocalFieldId = Idx<adt::FieldData>;
142 142
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
144pub struct ConstId(salsa::InternId); 144pub struct ConstId(salsa::InternId);
@@ -299,7 +299,7 @@ impl From<AssocItemId> for GenericDefId {
299#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 299#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
300pub enum AttrDefId { 300pub enum AttrDefId {
301 ModuleId(ModuleId), 301 ModuleId(ModuleId),
302 StructFieldId(StructFieldId), 302 FieldId(FieldId),
303 AdtId(AdtId), 303 AdtId(AdtId),
304 FunctionId(FunctionId), 304 FunctionId(FunctionId),
305 EnumVariantId(EnumVariantId), 305 EnumVariantId(EnumVariantId),
@@ -313,7 +313,7 @@ pub enum AttrDefId {
313 313
314impl_froms!( 314impl_froms!(
315 AttrDefId: ModuleId, 315 AttrDefId: ModuleId,
316 StructFieldId, 316 FieldId,
317 AdtId(StructId, EnumId, UnionId), 317 AdtId(StructId, EnumId, UnionId),
318 EnumVariantId, 318 EnumVariantId,
319 StaticId, 319 StaticId,
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs
index 9e5dfeab3..fdb49560b 100644
--- a/crates/ra_hir_ty/src/db.rs
+++ b/crates/ra_hir_ty/src/db.rs
@@ -3,7 +3,7 @@
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{ 5use hir_def::{
6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalStructFieldId, TraitId, TypeParamId, 6 db::DefDatabase, DefWithBodyId, GenericDefId, ImplId, LocalFieldId, TraitId, TypeParamId,
7 VariantId, 7 VariantId,
8}; 8};
9use ra_arena::map::ArenaMap; 9use ra_arena::map::ArenaMap;
@@ -43,7 +43,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>; 43 fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
44 44
45 #[salsa::invoke(crate::lower::field_types_query)] 45 #[salsa::invoke(crate::lower::field_types_query)]
46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>>; 46 fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
47 47
48 #[salsa::invoke(crate::callable_item_sig)] 48 #[salsa::invoke(crate::callable_item_sig)]
49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig; 49 fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig;
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index fd59f4320..f04968e14 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -24,7 +24,7 @@ pub use hir_def::{
24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, 24 ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp,
25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp, 25 MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, UnaryOp,
26 }, 26 },
27 LocalStructFieldId, VariantId, 27 LocalFieldId, VariantId,
28}; 28};
29 29
30pub struct ExprValidator<'a, 'b: 'a> { 30pub struct ExprValidator<'a, 'b: 'a> {
@@ -83,7 +83,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
83 id: ExprId, 83 id: ExprId,
84 db: &dyn HirDatabase, 84 db: &dyn HirDatabase,
85 variant_def: VariantId, 85 variant_def: VariantId,
86 missed_fields: Vec<LocalStructFieldId>, 86 missed_fields: Vec<LocalFieldId>,
87 ) { 87 ) {
88 // XXX: only look at source_map if we do have missing fields 88 // XXX: only look at source_map if we do have missing fields
89 let (_, source_map) = db.body_with_source_map(self.func.into()); 89 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -112,7 +112,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
112 id: PatId, 112 id: PatId,
113 db: &dyn HirDatabase, 113 db: &dyn HirDatabase,
114 variant_def: VariantId, 114 variant_def: VariantId,
115 missed_fields: Vec<LocalStructFieldId>, 115 missed_fields: Vec<LocalFieldId>,
116 ) { 116 ) {
117 // XXX: only look at source_map if we do have missing fields 117 // XXX: only look at source_map if we do have missing fields
118 let (_, source_map) = db.body_with_source_map(self.func.into()); 118 let (_, source_map) = db.body_with_source_map(self.func.into());
@@ -256,7 +256,7 @@ pub fn record_literal_missing_fields(
256 infer: &InferenceResult, 256 infer: &InferenceResult,
257 id: ExprId, 257 id: ExprId,
258 expr: &Expr, 258 expr: &Expr,
259) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 259) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
260 let (fields, exhausitve) = match expr { 260 let (fields, exhausitve) = match expr {
261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()), 261 Expr::RecordLit { path: _, fields, spread } => (fields, spread.is_none()),
262 _ => return None, 262 _ => return None,
@@ -270,7 +270,7 @@ pub fn record_literal_missing_fields(
270 let variant_data = variant_data(db.upcast(), variant_def); 270 let variant_data = variant_data(db.upcast(), variant_def);
271 271
272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 272 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
273 let missed_fields: Vec<LocalStructFieldId> = variant_data 273 let missed_fields: Vec<LocalFieldId> = variant_data
274 .fields() 274 .fields()
275 .iter() 275 .iter()
276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 276 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
@@ -286,7 +286,7 @@ pub fn record_pattern_missing_fields(
286 infer: &InferenceResult, 286 infer: &InferenceResult,
287 id: PatId, 287 id: PatId,
288 pat: &Pat, 288 pat: &Pat,
289) -> Option<(VariantId, Vec<LocalStructFieldId>, /*exhaustive*/ bool)> { 289) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
290 let (fields, exhaustive) = match pat { 290 let (fields, exhaustive) = match pat {
291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis), 291 Pat::Record { path: _, args, ellipsis } => (args, !ellipsis),
292 _ => return None, 292 _ => return None,
@@ -300,7 +300,7 @@ pub fn record_pattern_missing_fields(
300 let variant_data = variant_data(db.upcast(), variant_def); 300 let variant_data = variant_data(db.upcast(), variant_def);
301 301
302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); 302 let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
303 let missed_fields: Vec<LocalStructFieldId> = variant_data 303 let missed_fields: Vec<LocalFieldId> = variant_data
304 .fields() 304 .fields()
305 .iter() 305 .iter()
306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) }) 306 .filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index dfb6a435f..6a53be621 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -28,7 +28,7 @@ use hir_def::{
28 path::{path, Path}, 28 path::{path, Path},
29 resolver::{HasResolver, Resolver, TypeNs}, 29 resolver::{HasResolver, Resolver, TypeNs},
30 type_ref::{Mutability, TypeRef}, 30 type_ref::{Mutability, TypeRef},
31 AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TraitId, TypeAliasId, VariantId, 31 AdtId, AssocItemId, DefWithBodyId, FieldId, FunctionId, TraitId, TypeAliasId, VariantId,
32}; 32};
33use hir_expand::{diagnostics::DiagnosticSink, name::name}; 33use hir_expand::{diagnostics::DiagnosticSink, name::name};
34use ra_arena::map::ArenaMap; 34use ra_arena::map::ArenaMap;
@@ -124,10 +124,10 @@ pub struct InferenceResult {
124 /// For each method call expr, records the function it resolves to. 124 /// For each method call expr, records the function it resolves to.
125 method_resolutions: FxHashMap<ExprId, FunctionId>, 125 method_resolutions: FxHashMap<ExprId, FunctionId>,
126 /// For each field access expr, records the field it resolves to. 126 /// For each field access expr, records the field it resolves to.
127 field_resolutions: FxHashMap<ExprId, StructFieldId>, 127 field_resolutions: FxHashMap<ExprId, FieldId>,
128 /// For each field in record literal, records the field it resolves to. 128 /// For each field in record literal, records the field it resolves to.
129 record_field_resolutions: FxHashMap<ExprId, StructFieldId>, 129 record_field_resolutions: FxHashMap<ExprId, FieldId>,
130 record_field_pat_resolutions: FxHashMap<PatId, StructFieldId>, 130 record_field_pat_resolutions: FxHashMap<PatId, FieldId>,
131 /// For each struct literal, records the variant it resolves to. 131 /// For each struct literal, records the variant it resolves to.
132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>, 132 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>,
133 /// For each associated item record what it resolves to 133 /// For each associated item record what it resolves to
@@ -142,13 +142,13 @@ impl InferenceResult {
142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> { 142 pub fn method_resolution(&self, expr: ExprId) -> Option<FunctionId> {
143 self.method_resolutions.get(&expr).copied() 143 self.method_resolutions.get(&expr).copied()
144 } 144 }
145 pub fn field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 145 pub fn field_resolution(&self, expr: ExprId) -> Option<FieldId> {
146 self.field_resolutions.get(&expr).copied() 146 self.field_resolutions.get(&expr).copied()
147 } 147 }
148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<StructFieldId> { 148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<FieldId> {
149 self.record_field_resolutions.get(&expr).copied() 149 self.record_field_resolutions.get(&expr).copied()
150 } 150 }
151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<StructFieldId> { 151 pub fn record_field_pat_resolution(&self, pat: PatId) -> Option<FieldId> {
152 self.record_field_pat_resolutions.get(&pat).copied() 152 self.record_field_pat_resolutions.get(&pat).copied()
153 } 153 }
154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> { 154 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> {
@@ -249,7 +249,7 @@ impl<'a> InferenceContext<'a> {
249 self.result.method_resolutions.insert(expr, func); 249 self.result.method_resolutions.insert(expr, func);
250 } 250 }
251 251
252 fn write_field_resolution(&mut self, expr: ExprId, field: StructFieldId) { 252 fn write_field_resolution(&mut self, expr: ExprId, field: FieldId) {
253 self.result.field_resolutions.insert(expr, field); 253 self.result.field_resolutions.insert(expr, field);
254 } 254 }
255 255
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 1fdb235a0..83f946eee 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -8,7 +8,7 @@ use hir_def::{
8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
10 resolver::resolver_for_expr, 10 resolver::resolver_for_expr,
11 AdtId, AssocContainerId, Lookup, StructFieldId, 11 AdtId, AssocContainerId, FieldId, Lookup,
12}; 12};
13use hir_expand::name::Name; 13use hir_expand::name::Name;
14use ra_syntax::ast::RangeOp; 14use ra_syntax::ast::RangeOp;
@@ -216,9 +216,7 @@ impl<'a> InferenceContext<'a> {
216 for (field_idx, field) in fields.iter().enumerate() { 216 for (field_idx, field) in fields.iter().enumerate() {
217 let field_def = 217 let field_def =
218 variant_data.as_ref().and_then(|it| match it.field(&field.name) { 218 variant_data.as_ref().and_then(|it| match it.field(&field.name) {
219 Some(local_id) => { 219 Some(local_id) => Some(FieldId { parent: def_id.unwrap(), local_id }),
220 Some(StructFieldId { parent: def_id.unwrap(), local_id })
221 }
222 None => { 220 None => {
223 self.push_diagnostic(InferenceDiagnostic::NoSuchField { 221 self.push_diagnostic(InferenceDiagnostic::NoSuchField {
224 expr: tgt_expr, 222 expr: tgt_expr,
@@ -257,7 +255,7 @@ impl<'a> InferenceContext<'a> {
257 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), 255 .and_then(|idx| a_ty.parameters.0.get(idx).cloned()),
258 TypeCtor::Adt(AdtId::StructId(s)) => { 256 TypeCtor::Adt(AdtId::StructId(s)) => {
259 self.db.struct_data(s).variant_data.field(name).map(|local_id| { 257 self.db.struct_data(s).variant_data.field(name).map(|local_id| {
260 let field = StructFieldId { parent: s.into(), local_id }; 258 let field = FieldId { parent: s.into(), local_id };
261 self.write_field_resolution(tgt_expr, field); 259 self.write_field_resolution(tgt_expr, field);
262 self.db.field_types(s.into())[field.local_id] 260 self.db.field_types(s.into())[field.local_id]
263 .clone() 261 .clone()
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs
index 7c2ad4384..54ec870df 100644
--- a/crates/ra_hir_ty/src/infer/pat.rs
+++ b/crates/ra_hir_ty/src/infer/pat.rs
@@ -7,7 +7,7 @@ use hir_def::{
7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat}, 7 expr::{BindingAnnotation, Pat, PatId, RecordFieldPat},
8 path::Path, 8 path::Path,
9 type_ref::Mutability, 9 type_ref::Mutability,
10 StructFieldId, 10 FieldId,
11}; 11};
12use hir_expand::name::Name; 12use hir_expand::name::Name;
13use test_utils::tested_by; 13use test_utils::tested_by;
@@ -69,7 +69,7 @@ impl<'a> InferenceContext<'a> {
69 for subpat in subpats { 69 for subpat in subpats {
70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); 70 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name));
71 if let Some(local_id) = matching_field { 71 if let Some(local_id) = matching_field {
72 let field_def = StructFieldId { parent: def.unwrap(), local_id }; 72 let field_def = FieldId { parent: def.unwrap(), local_id };
73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def); 73 self.result.record_field_pat_resolutions.insert(subpat.pat, field_def);
74 } 74 }
75 75
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index c2812e178..b57214296 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -18,8 +18,8 @@ use hir_def::{
18 resolver::{HasResolver, Resolver, TypeNs}, 18 resolver::{HasResolver, Resolver, TypeNs},
19 type_ref::{TypeBound, TypeRef}, 19 type_ref::{TypeBound, TypeRef},
20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule, 20 AdtId, AssocContainerId, ConstId, EnumId, EnumVariantId, FunctionId, GenericDefId, HasModule,
21 ImplId, LocalStructFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, 21 ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
22 UnionId, VariantId, 22 VariantId,
23}; 23};
24use ra_arena::map::ArenaMap; 24use ra_arena::map::ArenaMap;
25use ra_db::CrateId; 25use ra_db::CrateId;
@@ -682,7 +682,7 @@ pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig {
682pub(crate) fn field_types_query( 682pub(crate) fn field_types_query(
683 db: &dyn HirDatabase, 683 db: &dyn HirDatabase,
684 variant_id: VariantId, 684 variant_id: VariantId,
685) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>> { 685) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>> {
686 let var_data = variant_data(db.upcast(), variant_id); 686 let var_data = variant_data(db.upcast(), variant_id);
687 let (resolver, def): (_, GenericDefId) = match variant_id { 687 let (resolver, def): (_, GenericDefId) = match variant_id {
688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()), 688 VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()),
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 9f9f06bf0..7633cd7fd 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -15,12 +15,7 @@ use crate::{
15}; 15};
16 16
17impl Completions { 17impl Completions {
18 pub(crate) fn add_field( 18 pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) {
19 &mut self,
20 ctx: &CompletionContext,
21 field: hir::StructField,
22 ty: &Type,
23 ) {
24 let is_deprecated = is_deprecated(field, ctx.db); 19 let is_deprecated = is_deprecated(field, ctx.db);
25 let ty = ty.display(ctx.db).to_string(); 20 let ty = ty.display(ctx.db).to_string();
26 let name = field.name(ctx.db); 21 let name = field.name(ctx.db);
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 67bc9c31b..914a8b471 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -189,7 +189,7 @@ impl TryToNav for Definition {
189 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 189 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
190 match self { 190 match self {
191 Definition::Macro(it) => Some(it.to_nav(db)), 191 Definition::Macro(it) => Some(it.to_nav(db)),
192 Definition::StructField(it) => Some(it.to_nav(db)), 192 Definition::Field(it) => Some(it.to_nav(db)),
193 Definition::ModuleDef(it) => it.try_to_nav(db), 193 Definition::ModuleDef(it) => it.try_to_nav(db),
194 Definition::SelfType(it) => Some(it.to_nav(db)), 194 Definition::SelfType(it) => Some(it.to_nav(db)),
195 Definition::Local(it) => Some(it.to_nav(db)), 195 Definition::Local(it) => Some(it.to_nav(db)),
@@ -286,7 +286,7 @@ impl ToNav for hir::ImplDef {
286 } 286 }
287} 287}
288 288
289impl ToNav for hir::StructField { 289impl ToNav for hir::Field {
290 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { 290 fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
291 let src = self.source(db); 291 let src = self.source(db);
292 292
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index fcc2ab7fb..58c799eca 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -76,7 +76,7 @@ fn hover_text(
76 76
77fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> { 77fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
78 match def { 78 match def {
79 Definition::StructField(f) => Some(f.parent_def(db).name(db)), 79 Definition::Field(f) => Some(f.parent_def(db).name(db)),
80 Definition::Local(l) => l.parent(db).name(db), 80 Definition::Local(l) => l.parent(db).name(db),
81 Definition::ModuleDef(md) => match md { 81 Definition::ModuleDef(md) => match md {
82 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) { 82 ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
@@ -116,7 +116,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, def: Definition) -> Option<Strin
116 let src = it.source(db); 116 let src = it.source(db);
117 hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value)), mod_path) 117 hover_text(src.value.doc_comment_text(), Some(macro_label(&src.value)), mod_path)
118 } 118 }
119 Definition::StructField(it) => { 119 Definition::Field(it) => {
120 let src = it.source(db); 120 let src = it.source(db);
121 match src.value { 121 match src.value {
122 FieldSource::Named(it) => { 122 FieldSource::Named(it) => {
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index a3970bf83..555ccf295 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -144,7 +144,7 @@ fn find_name(
144 144
145fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> { 145fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Option<ReferenceAccess> {
146 match def { 146 match def {
147 Definition::Local(_) | Definition::StructField(_) => {} 147 Definition::Local(_) | Definition::Field(_) => {}
148 _ => return None, 148 _ => return None,
149 }; 149 };
150 150
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index a8f320e2f..fd17bc9f2 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -51,12 +51,12 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil
51 let mut replacement_text = String::new(); 51 let mut replacement_text = String::new();
52 let file_id = reference.file_range.file_id; 52 let file_id = reference.file_range.file_id;
53 let range = match reference.kind { 53 let range = match reference.kind {
54 ReferenceKind::StructFieldShorthandForField => { 54 ReferenceKind::FieldShorthandForField => {
55 replacement_text.push_str(new_name); 55 replacement_text.push_str(new_name);
56 replacement_text.push_str(": "); 56 replacement_text.push_str(": ");
57 TextRange::new(reference.file_range.range.start(), reference.file_range.range.start()) 57 TextRange::new(reference.file_range.range.start(), reference.file_range.range.start())
58 } 58 }
59 ReferenceKind::StructFieldShorthandForLocal => { 59 ReferenceKind::FieldShorthandForLocal => {
60 replacement_text.push_str(": "); 60 replacement_text.push_str(": ");
61 replacement_text.push_str(new_name); 61 replacement_text.push_str(new_name);
62 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end()) 62 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end())
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 6f02614a6..be0f8c827 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -422,7 +422,7 @@ fn highlight_element(
422fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { 422fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
423 match def { 423 match def {
424 Definition::Macro(_) => HighlightTag::Macro, 424 Definition::Macro(_) => HighlightTag::Macro,
425 Definition::StructField(_) => HighlightTag::Field, 425 Definition::Field(_) => HighlightTag::Field,
426 Definition::ModuleDef(def) => match def { 426 Definition::ModuleDef(def) => match def {
427 hir::ModuleDef::Module(_) => HighlightTag::Module, 427 hir::ModuleDef::Module(_) => HighlightTag::Module,
428 hir::ModuleDef::Function(_) => HighlightTag::Function, 428 hir::ModuleDef::Function(_) => HighlightTag::Function,
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 785613b82..7cd2384e9 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -6,8 +6,8 @@
6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). 6// FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
7 7
8use hir::{ 8use hir::{
9 HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution, Semantics, 9 Field, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution,
10 StructField, TypeParam, Visibility, 10 Semantics, TypeParam, Visibility,
11}; 11};
12use ra_prof::profile; 12use ra_prof::profile;
13use ra_syntax::{ 13use ra_syntax::{
@@ -22,7 +22,7 @@ use crate::RootDatabase;
22#[derive(Debug, PartialEq, Eq)] 22#[derive(Debug, PartialEq, Eq)]
23pub enum Definition { 23pub enum Definition {
24 Macro(MacroDef), 24 Macro(MacroDef),
25 StructField(StructField), 25 Field(Field),
26 ModuleDef(ModuleDef), 26 ModuleDef(ModuleDef),
27 SelfType(ImplDef), 27 SelfType(ImplDef),
28 Local(Local), 28 Local(Local),
@@ -33,7 +33,7 @@ impl Definition {
33 pub fn module(&self, db: &RootDatabase) -> Option<Module> { 33 pub fn module(&self, db: &RootDatabase) -> Option<Module> {
34 match self { 34 match self {
35 Definition::Macro(it) => it.module(db), 35 Definition::Macro(it) => it.module(db),
36 Definition::StructField(it) => Some(it.parent_def(db).module(db)), 36 Definition::Field(it) => Some(it.parent_def(db).module(db)),
37 Definition::ModuleDef(it) => it.module(db), 37 Definition::ModuleDef(it) => it.module(db),
38 Definition::SelfType(it) => Some(it.module(db)), 38 Definition::SelfType(it) => Some(it.module(db)),
39 Definition::Local(it) => Some(it.module(db)), 39 Definition::Local(it) => Some(it.module(db)),
@@ -46,7 +46,7 @@ impl Definition {
46 46
47 match self { 47 match self {
48 Definition::Macro(_) => None, 48 Definition::Macro(_) => None,
49 Definition::StructField(sf) => Some(sf.visibility(db)), 49 Definition::Field(sf) => Some(sf.visibility(db)),
50 Definition::ModuleDef(def) => module?.visibility_of(db, def), 50 Definition::ModuleDef(def) => module?.visibility_of(db, def),
51 Definition::SelfType(_) => None, 51 Definition::SelfType(_) => None,
52 Definition::Local(_) => None, 52 Definition::Local(_) => None,
@@ -57,7 +57,7 @@ impl Definition {
57 pub fn name(&self, db: &RootDatabase) -> Option<Name> { 57 pub fn name(&self, db: &RootDatabase) -> Option<Name> {
58 let name = match self { 58 let name = match self {
59 Definition::Macro(it) => it.name(db)?, 59 Definition::Macro(it) => it.name(db)?,
60 Definition::StructField(it) => it.name(db), 60 Definition::Field(it) => it.name(db),
61 Definition::ModuleDef(def) => match def { 61 Definition::ModuleDef(def) => match def {
62 hir::ModuleDef::Module(it) => it.name(db)?, 62 hir::ModuleDef::Module(it) => it.name(db)?,
63 hir::ModuleDef::Function(it) => it.name(db), 63 hir::ModuleDef::Function(it) => it.name(db),
@@ -124,8 +124,8 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
124 Some(Definition::Local(local)) 124 Some(Definition::Local(local))
125 }, 125 },
126 ast::RecordFieldDef(it) => { 126 ast::RecordFieldDef(it) => {
127 let field: hir::StructField = sema.to_def(&it)?; 127 let field: hir::Field = sema.to_def(&it)?;
128 Some(Definition::StructField(field)) 128 Some(Definition::Field(field))
129 }, 129 },
130 ast::Module(it) => { 130 ast::Module(it) => {
131 let def = sema.to_def(&it)?; 131 let def = sema.to_def(&it)?;
@@ -213,7 +213,7 @@ pub fn classify_name_ref(
213 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { 213 if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
214 tested_by!(goto_def_for_fields; force); 214 tested_by!(goto_def_for_fields; force);
215 if let Some(field) = sema.resolve_field(&field_expr) { 215 if let Some(field) = sema.resolve_field(&field_expr) {
216 return Some(NameRefClass::Definition(Definition::StructField(field))); 216 return Some(NameRefClass::Definition(Definition::Field(field)));
217 } 217 }
218 } 218 }
219 219
@@ -221,7 +221,7 @@ pub fn classify_name_ref(
221 tested_by!(goto_def_for_record_fields; force); 221 tested_by!(goto_def_for_record_fields; force);
222 tested_by!(goto_def_for_field_init_shorthand; force); 222 tested_by!(goto_def_for_field_init_shorthand; force);
223 if let Some((field, local)) = sema.resolve_record_field(&record_field) { 223 if let Some((field, local)) = sema.resolve_record_field(&record_field) {
224 let field = Definition::StructField(field); 224 let field = Definition::Field(field);
225 let res = match local { 225 let res = match local {
226 None => NameRefClass::Definition(field), 226 None => NameRefClass::Definition(field),
227 Some(local) => NameRefClass::FieldShorthand { field, local }, 227 Some(local) => NameRefClass::FieldShorthand { field, local },
@@ -233,7 +233,7 @@ pub fn classify_name_ref(
233 if let Some(record_field_pat) = ast::RecordFieldPat::cast(parent.clone()) { 233 if let Some(record_field_pat) = ast::RecordFieldPat::cast(parent.clone()) {
234 tested_by!(goto_def_for_record_field_pats; force); 234 tested_by!(goto_def_for_record_field_pats; force);
235 if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) { 235 if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) {
236 let field = Definition::StructField(field); 236 let field = Definition::Field(field);
237 return Some(NameRefClass::Definition(field)); 237 return Some(NameRefClass::Definition(field));
238 } 238 }
239 } 239 }
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index 596f957b8..b464959fc 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -28,8 +28,8 @@ pub struct Reference {
28 28
29#[derive(Debug, Clone, PartialEq)] 29#[derive(Debug, Clone, PartialEq)]
30pub enum ReferenceKind { 30pub enum ReferenceKind {
31 StructFieldShorthandForField, 31 FieldShorthandForField,
32 StructFieldShorthandForLocal, 32 FieldShorthandForLocal,
33 StructLiteral, 33 StructLiteral,
34 Other, 34 Other,
35} 35}
@@ -242,14 +242,14 @@ impl Definition {
242 } 242 }
243 Some(NameRefClass::FieldShorthand { local, field }) => { 243 Some(NameRefClass::FieldShorthand { local, field }) => {
244 match self { 244 match self {
245 Definition::StructField(_) if &field == self => refs.push(Reference { 245 Definition::Field(_) if &field == self => refs.push(Reference {
246 file_range: sema.original_range(name_ref.syntax()), 246 file_range: sema.original_range(name_ref.syntax()),
247 kind: ReferenceKind::StructFieldShorthandForField, 247 kind: ReferenceKind::FieldShorthandForField,
248 access: reference_access(&field, &name_ref), 248 access: reference_access(&field, &name_ref),
249 }), 249 }),
250 Definition::Local(l) if &local == l => refs.push(Reference { 250 Definition::Local(l) if &local == l => refs.push(Reference {
251 file_range: sema.original_range(name_ref.syntax()), 251 file_range: sema.original_range(name_ref.syntax()),
252 kind: ReferenceKind::StructFieldShorthandForLocal, 252 kind: ReferenceKind::FieldShorthandForLocal,
253 access: reference_access(&Definition::Local(local), &name_ref), 253 access: reference_access(&Definition::Local(local), &name_ref),
254 }), 254 }),
255 255
@@ -267,7 +267,7 @@ impl Definition {
267fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> { 267fn reference_access(def: &Definition, name_ref: &ast::NameRef) -> Option<ReferenceAccess> {
268 // Only Locals and Fields have accesses for now. 268 // Only Locals and Fields have accesses for now.
269 match def { 269 match def {
270 Definition::Local(_) | Definition::StructField(_) => {} 270 Definition::Local(_) | Definition::Field(_) => {}
271 _ => return None, 271 _ => return None,
272 }; 272 };
273 273