From 970dbf871795650ecf49b7198d53bdcad9c612af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 14:23:34 +0200 Subject: Rename StructField -> Field --- crates/ra_hir/src/code_model.rs | 34 ++++++++++++++-------------- crates/ra_hir/src/from_id.rs | 22 +++++++++--------- crates/ra_hir/src/has_source.rs | 6 ++--- crates/ra_hir/src/lib.rs | 4 ++-- crates/ra_hir/src/semantics.rs | 27 ++++++++-------------- crates/ra_hir/src/semantics/source_to_def.rs | 8 +++---- crates/ra_hir/src/source_analyzer.rs | 22 +++++++++--------- 7 files changed, 57 insertions(+), 66 deletions(-) (limited to 'crates/ra_hir') 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::{ resolver::{HasResolver, Resolver}, type_ref::{Mutability, TypeRef}, AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, - ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, - StructId, TraitId, TypeAliasId, TypeParamId, UnionId, + ImplId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId, + TraitId, TypeAliasId, TypeParamId, UnionId, }; use hir_expand::{ diagnostics::DiagnosticSink, @@ -294,9 +294,9 @@ impl Module { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct StructField { +pub struct Field { pub(crate) parent: VariantDef, - pub(crate) id: LocalStructFieldId, + pub(crate) id: LocalFieldId, } #[derive(Debug, PartialEq, Eq)] @@ -305,7 +305,7 @@ pub enum FieldSource { Pos(ast::TupleFieldDef), } -impl StructField { +impl Field { pub fn name(&self, db: &dyn HirDatabase) -> Name { self.parent.variant_data(db).fields()[self.id].name.clone() } @@ -331,7 +331,7 @@ impl StructField { } } -impl HasVisibility for StructField { +impl HasVisibility for Field { fn visibility(&self, db: &dyn HirDatabase) -> Visibility { let variant_data = self.parent.variant_data(db); let visibility = &variant_data.fields()[self.id].visibility; @@ -358,12 +358,12 @@ impl Struct { db.struct_data(self.id).name.clone() } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn HirDatabase) -> Vec { db.struct_data(self.id) .variant_data .fields() .iter() - .map(|(id, _)| StructField { parent: self.into(), id }) + .map(|(id, _)| Field { parent: self.into(), id }) .collect() } @@ -394,12 +394,12 @@ impl Union { Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn HirDatabase) -> Vec { db.union_data(self.id) .variant_data .fields() .iter() - .map(|(id, _)| StructField { parent: self.into(), id }) + .map(|(id, _)| Field { parent: self.into(), id }) .collect() } @@ -457,11 +457,11 @@ impl EnumVariant { db.enum_data(self.parent.id).variants[self.id].name.clone() } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn HirDatabase) -> Vec { self.variant_data(db) .fields() .iter() - .map(|(id, _)| StructField { parent: self.into(), id }) + .map(|(id, _)| Field { parent: self.into(), id }) .collect() } @@ -527,7 +527,7 @@ pub enum VariantDef { impl_froms!(VariantDef: Struct, Union, EnumVariant); impl VariantDef { - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn HirDatabase) -> Vec { match self { VariantDef::Struct(it) => it.fields(db), VariantDef::Union(it) => it.fields(db), @@ -1148,7 +1148,7 @@ impl Type { } } - pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(StructField, Type)> { + pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { if let Ty::Apply(a_ty) = &self.ty.value { if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor { let var_def = s.into(); @@ -1156,7 +1156,7 @@ impl Type { .field_types(var_def) .iter() .map(|(local_id, ty)| { - let def = StructField { parent: var_def.into(), id: local_id }; + let def = Field { parent: var_def.into(), id: local_id }; let ty = ty.clone().subst(&a_ty.parameters); (def, self.derived(ty)) }) @@ -1352,7 +1352,7 @@ impl ScopeDef { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum AttrDef { Module(Module), - StructField(StructField), + Field(Field), Adt(Adt), Function(Function), EnumVariant(EnumVariant), @@ -1365,7 +1365,7 @@ pub enum AttrDef { impl_froms!( AttrDef: Module, - StructField, + Field, Adt(Struct, Enum, Union), EnumVariant, 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 @@ //! are splitting the hir. use hir_def::{ - expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, GenericDefId, - ModuleDefId, StructFieldId, VariantId, + expr::PatId, AdtId, AssocItemId, AttrDefId, DefWithBodyId, EnumVariantId, FieldId, + GenericDefId, ModuleDefId, VariantId, }; use crate::{ - code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, Local, - MacroDef, ModuleDef, StructField, VariantDef, + code_model::ItemInNs, Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, Field, GenericDef, + Local, MacroDef, ModuleDef, VariantDef, }; macro_rules! from_id { @@ -184,15 +184,15 @@ impl From for VariantId { } } -impl From for StructFieldId { - fn from(def: StructField) -> Self { - StructFieldId { parent: def.parent.into(), local_id: def.id } +impl From for FieldId { + fn from(def: Field) -> Self { + FieldId { parent: def.parent.into(), local_id: def.id } } } -impl From for StructField { - fn from(def: StructFieldId) -> Self { - StructField { parent: def.parent.into(), id: def.local_id } +impl From for Field { + fn from(def: FieldId) -> Self { + Field { parent: def.parent.into(), id: def.local_id } } } @@ -200,7 +200,7 @@ impl From for AttrDefId { fn from(def: AttrDef) -> Self { match def { AttrDef::Module(it) => AttrDefId::ModuleId(it.id), - AttrDef::StructField(it) => AttrDefId::StructFieldId(it.into()), + AttrDef::Field(it) => AttrDefId::FieldId(it.into()), AttrDef::Adt(it) => AttrDefId::AdtId(it.into()), AttrDef::Function(it) => AttrDefId::FunctionId(it.id), 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::{ use ra_syntax::ast; use crate::{ - db::HirDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplDef, MacroDef, Module, - Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, + db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, ImplDef, MacroDef, + Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, }; pub use hir_expand::InFile; @@ -37,7 +37,7 @@ impl Module { } } -impl HasSource for StructField { +impl HasSource for Field { type Ast = FieldSource; fn source(self, db: &dyn HirDatabase) -> InFile { 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; pub use crate::{ code_model::{ Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Const, Crate, CrateDependency, - DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, + DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, - StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, + Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, }, has_source::HasSource, 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::{ diagnostics::Diagnostic, semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, source_analyzer::{resolve_hir_path, SourceAnalyzer}, - AssocItem, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, Name, - Origin, Path, ScopeDef, StructField, Trait, Type, TypeParam, + AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, + Name, Origin, Path, ScopeDef, Trait, Type, TypeParam, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -184,18 +184,15 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.analyze(call.syntax()).resolve_method_call(self.db, call) } - pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option { + pub fn resolve_field(&self, field: &ast::FieldExpr) -> Option { self.analyze(field.syntax()).resolve_field(self.db, field) } - pub fn resolve_record_field( - &self, - field: &ast::RecordField, - ) -> Option<(StructField, Option)> { + pub fn resolve_record_field(&self, field: &ast::RecordField) -> Option<(Field, Option)> { self.analyze(field.syntax()).resolve_record_field(self.db, field) } - pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option { + pub fn resolve_record_field_pat(&self, field: &ast::RecordFieldPat) -> Option { self.analyze(field.syntax()).resolve_record_field_pat(self.db, field) } @@ -216,19 +213,13 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { // FIXME: use this instead? // pub fn resolve_name_ref(&self, name_ref: &ast::NameRef) -> Option; - pub fn record_literal_missing_fields( - &self, - literal: &ast::RecordLit, - ) -> Vec<(StructField, Type)> { + pub fn record_literal_missing_fields(&self, literal: &ast::RecordLit) -> Vec<(Field, Type)> { self.analyze(literal.syntax()) .record_literal_missing_fields(self.db, literal) .unwrap_or_default() } - pub fn record_pattern_missing_fields( - &self, - pattern: &ast::RecordPat, - ) -> Vec<(StructField, Type)> { + pub fn record_pattern_missing_fields(&self, pattern: &ast::RecordPat) -> Vec<(Field, Type)> { self.analyze(pattern.syntax()) .record_pattern_missing_fields(self.db, pattern) .unwrap_or_default() @@ -359,8 +350,8 @@ to_def_impls![ (crate::Const, ast::ConstDef, const_to_def), (crate::Static, ast::StaticDef, static_to_def), (crate::Function, ast::FnDef, fn_to_def), - (crate::StructField, ast::RecordFieldDef, record_field_to_def), - (crate::StructField, ast::TupleFieldDef, tuple_field_to_def), + (crate::Field, ast::RecordFieldDef, record_field_to_def), + (crate::Field, ast::TupleFieldDef, tuple_field_to_def), (crate::EnumVariant, ast::EnumVariant, enum_variant_to_def), (crate::TypeParam, ast::TypeParam, type_param_to_def), (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::{ dyn_map::DynMap, expr::PatId, keys::{self, Key}, - ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, ImplId, ModuleId, - StaticId, StructFieldId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, + ConstId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId, GenericDefId, ImplId, + ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, }; use hir_expand::{name::AsName, AstId, MacroDefKind}; use ra_db::FileId; @@ -97,13 +97,13 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn record_field_to_def( &mut self, src: InFile, - ) -> Option { + ) -> Option { self.to_def(src, keys::RECORD_FIELD) } pub(super) fn tuple_field_to_def( &mut self, src: InFile, - ) -> Option { + ) -> Option { self.to_def(src, keys::TUPLE_FIELD) } 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::{ }, expr::{ExprId, Pat, PatId}, resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs}, - AsMacroCall, DefWithBodyId, LocalStructFieldId, StructFieldId, VariantId, + AsMacroCall, DefWithBodyId, FieldId, LocalFieldId, VariantId, }; use hir_expand::{hygiene::Hygiene, name::AsName, HirFileId, InFile}; use hir_ty::{ @@ -27,8 +27,8 @@ use ra_syntax::{ }; use crate::{ - db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Function, Local, MacroDef, - ModPath, ModuleDef, Path, PathKind, Static, Struct, StructField, Trait, Type, TypeAlias, + db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local, + MacroDef, ModPath, ModuleDef, Path, PathKind, Static, Struct, Trait, Type, TypeAlias, TypeParam, }; use ra_db::CrateId; @@ -140,7 +140,7 @@ impl SourceAnalyzer { &self, db: &dyn HirDatabase, field: &ast::FieldExpr, - ) -> Option { + ) -> Option { let expr_id = self.expr_id(db, &field.clone().into())?; self.infer.as_ref()?.field_resolution(expr_id).map(|it| it.into()) } @@ -149,7 +149,7 @@ impl SourceAnalyzer { &self, db: &dyn HirDatabase, field: &ast::RecordField, - ) -> Option<(StructField, Option)> { + ) -> Option<(Field, Option)> { let expr = field.expr()?; let expr_id = self.expr_id(db, &expr)?; let local = if field.name_ref().is_some() { @@ -172,7 +172,7 @@ impl SourceAnalyzer { &self, _db: &dyn HirDatabase, field: &ast::RecordFieldPat, - ) -> Option { + ) -> Option { let pat_id = self.pat_id(&field.pat()?)?; let struct_field = self.infer.as_ref()?.record_field_pat_resolution(pat_id)?; Some(struct_field.into()) @@ -232,7 +232,7 @@ impl SourceAnalyzer { &self, db: &dyn HirDatabase, literal: &ast::RecordLit, - ) -> Option> { + ) -> Option> { let krate = self.resolver.krate()?; let body = self.body.as_ref()?; let infer = self.infer.as_ref()?; @@ -253,7 +253,7 @@ impl SourceAnalyzer { &self, db: &dyn HirDatabase, pattern: &ast::RecordPat, - ) -> Option> { + ) -> Option> { let krate = self.resolver.krate()?; let body = self.body.as_ref()?; let infer = self.infer.as_ref()?; @@ -276,14 +276,14 @@ impl SourceAnalyzer { krate: CrateId, substs: &Substs, variant: VariantId, - missing_fields: Vec, - ) -> Vec<(StructField, Type)> { + missing_fields: Vec, + ) -> Vec<(Field, Type)> { let field_types = db.field_types(variant); missing_fields .into_iter() .map(|local_id| { - let field = StructFieldId { parent: variant, local_id }; + let field = FieldId { parent: variant, local_id }; let ty = field_types[local_id].clone().subst(substs); (field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty)) }) -- cgit v1.2.3