From f6ed16674c461cb20c39e787fffab2269b9629b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 20 Dec 2020 10:05:24 +0300 Subject: Align code_model name with ungrammar --- crates/hir/src/attrs.rs | 6 +++--- crates/hir/src/code_model.rs | 44 ++++++++++++++++++--------------------- crates/hir/src/from_id.rs | 23 ++++++++++---------- crates/hir/src/has_source.rs | 6 +++--- crates/hir/src/lib.rs | 6 +++--- crates/hir/src/semantics.rs | 4 ++-- crates/hir/src/source_analyzer.rs | 18 ++++++++-------- 7 files changed, 51 insertions(+), 56 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 1f2ee2580..d32ce37ed 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -10,8 +10,8 @@ use hir_ty::db::HirDatabase; use syntax::ast; use crate::{ - Adt, Const, Enum, EnumVariant, Field, Function, MacroDef, Module, ModuleDef, Static, Struct, - Trait, TypeAlias, Union, + Adt, Const, Enum, Field, Function, MacroDef, Module, ModuleDef, Static, Struct, Trait, + TypeAlias, Union, Variant, }; pub trait HasAttrs { @@ -53,7 +53,7 @@ macro_rules! impl_has_attrs { impl_has_attrs![ (Field, FieldId), - (EnumVariant, EnumVariantId), + (Variant, EnumVariantId), (Static, StaticId), (Const, ConstId), (Trait, TraitId), diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 3248f6d20..d6c7e71ea 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -161,7 +161,7 @@ pub enum ModuleDef { Function(Function), Adt(Adt), // Can't be directly declared, but can be imported. - EnumVariant(EnumVariant), + Variant(Variant), Const(Const), Static(Static), Trait(Trait), @@ -172,7 +172,7 @@ impl_from!( Module, Function, Adt(Struct, Enum, Union), - EnumVariant, + Variant, Const, Static, Trait, @@ -186,7 +186,7 @@ impl From for ModuleDef { match var { VariantDef::Struct(t) => Adt::from(t).into(), VariantDef::Union(t) => Adt::from(t).into(), - VariantDef::EnumVariant(t) => t.into(), + VariantDef::Variant(t) => t.into(), } } } @@ -197,7 +197,7 @@ impl ModuleDef { ModuleDef::Module(it) => it.parent(db), ModuleDef::Function(it) => Some(it.module(db)), ModuleDef::Adt(it) => Some(it.module(db)), - ModuleDef::EnumVariant(it) => Some(it.module(db)), + ModuleDef::Variant(it) => Some(it.module(db)), ModuleDef::Const(it) => Some(it.module(db)), ModuleDef::Static(it) => Some(it.module(db)), ModuleDef::Trait(it) => Some(it.module(db)), @@ -221,7 +221,7 @@ impl ModuleDef { ModuleDef::Module(it) => it.parent(db)?, ModuleDef::Function(it) => return Some(it.visibility(db)), ModuleDef::Adt(it) => it.module(db), - ModuleDef::EnumVariant(it) => { + ModuleDef::Variant(it) => { let parent = it.parent_enum(db); let module = it.module(db); return module.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent))); @@ -241,7 +241,7 @@ impl ModuleDef { ModuleDef::Adt(it) => Some(it.name(db)), ModuleDef::Trait(it) => Some(it.name(db)), ModuleDef::Function(it) => Some(it.name(db)), - ModuleDef::EnumVariant(it) => Some(it.name(db)), + ModuleDef::Variant(it) => Some(it.name(db)), ModuleDef::TypeAlias(it) => Some(it.name(db)), ModuleDef::Module(it) => it.name(db), ModuleDef::Const(it) => it.name(db), @@ -455,7 +455,7 @@ impl Field { let generic_def_id: GenericDefId = match self.parent { VariantDef::Struct(it) => it.id.into(), VariantDef::Union(it) => it.id.into(), - VariantDef::EnumVariant(it) => it.parent.id.into(), + VariantDef::Variant(it) => it.parent.id.into(), }; let substs = Substs::type_params(db, generic_def_id); let ty = db.field_types(var_id)[self.id].clone().subst(&substs); @@ -566,12 +566,8 @@ impl Enum { db.enum_data(self.id).name.clone() } - pub fn variants(self, db: &dyn HirDatabase) -> Vec { - db.enum_data(self.id) - .variants - .iter() - .map(|(id, _)| EnumVariant { parent: self, id }) - .collect() + pub fn variants(self, db: &dyn HirDatabase) -> Vec { + db.enum_data(self.id).variants.iter().map(|(id, _)| Variant { parent: self, id }).collect() } pub fn ty(self, db: &dyn HirDatabase) -> Type { @@ -580,12 +576,12 @@ impl Enum { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct EnumVariant { +pub struct Variant { pub(crate) parent: Enum, pub(crate) id: LocalEnumVariantId, } -impl EnumVariant { +impl Variant { pub fn module(self, db: &dyn HirDatabase) -> Module { self.parent.module(db) } @@ -662,16 +658,16 @@ impl Adt { pub enum VariantDef { Struct(Struct), Union(Union), - EnumVariant(EnumVariant), + Variant(Variant), } -impl_from!(Struct, Union, EnumVariant for VariantDef); +impl_from!(Struct, Union, Variant for VariantDef); impl VariantDef { pub fn fields(self, db: &dyn HirDatabase) -> Vec { match self { VariantDef::Struct(it) => it.fields(db), VariantDef::Union(it) => it.fields(db), - VariantDef::EnumVariant(it) => it.fields(db), + VariantDef::Variant(it) => it.fields(db), } } @@ -679,7 +675,7 @@ impl VariantDef { match self { VariantDef::Struct(it) => it.module(db), VariantDef::Union(it) => it.module(db), - VariantDef::EnumVariant(it) => it.module(db), + VariantDef::Variant(it) => it.module(db), } } @@ -687,7 +683,7 @@ impl VariantDef { match self { VariantDef::Struct(s) => s.name(db), VariantDef::Union(u) => u.name(db), - VariantDef::EnumVariant(e) => e.name(db), + VariantDef::Variant(e) => e.name(db), } } @@ -695,7 +691,7 @@ impl VariantDef { match self { VariantDef::Struct(it) => it.variant_data(db), VariantDef::Union(it) => it.variant_data(db), - VariantDef::EnumVariant(it) => it.variant_data(db), + VariantDef::Variant(it) => it.variant_data(db), } } } @@ -1095,7 +1091,7 @@ pub enum GenericDef { Impl(Impl), // enum variants cannot have generics themselves, but their parent enums // can, and this makes some code easier to write - EnumVariant(EnumVariant), + Variant(Variant), // consts can have type parameters from their parents (i.e. associated consts of traits) Const(Const), } @@ -1105,7 +1101,7 @@ impl_from!( Trait, TypeAlias, Impl, - EnumVariant, + Variant, Const for GenericDef ); @@ -1847,7 +1843,7 @@ pub struct Callable { pub enum CallableKind { Function(Function), TupleStruct(Struct), - TupleEnumVariant(EnumVariant), + TupleEnumVariant(Variant), Closure, } diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index 8d0f84508..8e0c571b8 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs @@ -9,8 +9,7 @@ use hir_def::{ }; use crate::{ - Adt, AssocItem, DefWithBody, EnumVariant, Field, GenericDef, Local, MacroDef, ModuleDef, - VariantDef, + Adt, AssocItem, DefWithBody, Field, GenericDef, Local, MacroDef, ModuleDef, Variant, VariantDef, }; macro_rules! from_id { @@ -65,14 +64,14 @@ impl From for AdtId { } } -impl From for EnumVariant { +impl From for Variant { fn from(id: EnumVariantId) -> Self { - EnumVariant { parent: id.parent.into(), id: id.local_id } + Variant { parent: id.parent.into(), id: id.local_id } } } -impl From for EnumVariantId { - fn from(def: EnumVariant) -> Self { +impl From for EnumVariantId { + fn from(def: Variant) -> Self { EnumVariantId { parent: def.parent.id, local_id: def.id } } } @@ -83,7 +82,7 @@ impl From for ModuleDef { ModuleDefId::ModuleId(it) => ModuleDef::Module(it.into()), ModuleDefId::FunctionId(it) => ModuleDef::Function(it.into()), ModuleDefId::AdtId(it) => ModuleDef::Adt(it.into()), - ModuleDefId::EnumVariantId(it) => ModuleDef::EnumVariant(it.into()), + ModuleDefId::EnumVariantId(it) => ModuleDef::Variant(it.into()), ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()), ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()), ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()), @@ -99,7 +98,7 @@ impl From for ModuleDefId { ModuleDef::Module(it) => ModuleDefId::ModuleId(it.into()), ModuleDef::Function(it) => ModuleDefId::FunctionId(it.into()), ModuleDef::Adt(it) => ModuleDefId::AdtId(it.into()), - ModuleDef::EnumVariant(it) => ModuleDefId::EnumVariantId(it.into()), + ModuleDef::Variant(it) => ModuleDefId::EnumVariantId(it.into()), ModuleDef::Const(it) => ModuleDefId::ConstId(it.into()), ModuleDef::Static(it) => ModuleDefId::StaticId(it.into()), ModuleDef::Trait(it) => ModuleDefId::TraitId(it.into()), @@ -147,7 +146,7 @@ impl From for GenericDefId { GenericDef::Trait(it) => GenericDefId::TraitId(it.id), GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id), GenericDef::Impl(it) => GenericDefId::ImplId(it.id), - GenericDef::EnumVariant(it) => { + GenericDef::Variant(it) => { GenericDefId::EnumVariantId(EnumVariantId { parent: it.parent.id, local_id: it.id }) } GenericDef::Const(it) => GenericDefId::ConstId(it.id), @@ -164,7 +163,7 @@ impl From for GenericDef { GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()), GenericDefId::ImplId(it) => GenericDef::Impl(it.into()), GenericDefId::EnumVariantId(it) => { - GenericDef::EnumVariant(EnumVariant { parent: it.parent.into(), id: it.local_id }) + GenericDef::Variant(Variant { parent: it.parent.into(), id: it.local_id }) } GenericDefId::ConstId(it) => GenericDef::Const(it.into()), } @@ -185,7 +184,7 @@ impl From for VariantDef { fn from(def: VariantId) -> Self { match def { VariantId::StructId(it) => VariantDef::Struct(it.into()), - VariantId::EnumVariantId(it) => VariantDef::EnumVariant(it.into()), + VariantId::EnumVariantId(it) => VariantDef::Variant(it.into()), VariantId::UnionId(it) => VariantDef::Union(it.into()), } } @@ -195,7 +194,7 @@ impl From for VariantId { fn from(def: VariantDef) -> Self { match def { VariantDef::Struct(it) => VariantId::StructId(it.id), - VariantDef::EnumVariant(it) => VariantId::EnumVariantId(it.into()), + VariantDef::Variant(it) => VariantId::EnumVariantId(it.into()), VariantDef::Union(it) => VariantId::UnionId(it.id), } } diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index c5b81b252..0dc07c33e 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -10,8 +10,8 @@ use hir_expand::InFile; use syntax::ast; use crate::{ - db::HirDatabase, Const, Enum, EnumVariant, Field, FieldSource, Function, Impl, LifetimeParam, - MacroDef, Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, + db::HirDatabase, Const, Enum, Field, FieldSource, Function, Impl, LifetimeParam, MacroDef, + Module, Static, Struct, Trait, TypeAlias, TypeParam, Union, Variant, }; pub trait HasSource { @@ -73,7 +73,7 @@ impl HasSource for Enum { self.id.lookup(db.upcast()).source(db.upcast()) } } -impl HasSource for EnumVariant { +impl HasSource for Variant { type Ast = ast::Variant; fn source(self, db: &dyn HirDatabase) -> InFile { self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone()) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 3f4f8d8e4..bdd270c58 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -34,9 +34,9 @@ pub use crate::{ attrs::{HasAttrs, Namespace}, code_model::{ Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, - Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, - GenericDef, HasVisibility, Impl, LifetimeParam, Local, MacroDef, Module, ModuleDef, - ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, + Crate, CrateDependency, DefWithBody, Enum, Field, FieldSource, Function, GenericDef, + HasVisibility, Impl, LifetimeParam, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, + Struct, Trait, Type, TypeAlias, TypeParam, Union, Variant, VariantDef, }, has_source::HasSource, semantics::{PathResolution, Semantics, SemanticsScope}, diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 83ec91f58..25ebf73d8 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -51,7 +51,7 @@ impl PathResolution { Some(TypeNs::BuiltinType(*builtin)) } PathResolution::Def(ModuleDef::Const(_)) - | PathResolution::Def(ModuleDef::EnumVariant(_)) + | PathResolution::Def(ModuleDef::Variant(_)) | PathResolution::Def(ModuleDef::Function(_)) | PathResolution::Def(ModuleDef::Module(_)) | PathResolution::Def(ModuleDef::Static(_)) @@ -715,7 +715,7 @@ to_def_impls![ (crate::Function, ast::Fn, fn_to_def), (crate::Field, ast::RecordField, record_field_to_def), (crate::Field, ast::TupleField, tuple_field_to_def), - (crate::EnumVariant, ast::Variant, enum_variant_to_def), + (crate::Variant, ast::Variant, enum_variant_to_def), (crate::TypeParam, ast::TypeParam, type_param_to_def), (crate::LifetimeParam, ast::LifetimeParam, lifetime_param_to_def), (crate::MacroDef, ast::MacroRules, macro_rules_to_def), diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index bf0c959fe..bddc49c05 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -28,8 +28,8 @@ use syntax::{ }; use crate::{ - db::HirDatabase, semantics::PathResolution, Adt, Const, EnumVariant, Field, Function, Local, - MacroDef, ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, + db::HirDatabase, semantics::PathResolution, Adt, Const, Field, Function, Local, MacroDef, + ModuleDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Variant, }; use base_db::CrateId; @@ -230,7 +230,7 @@ impl SourceAnalyzer { if let Some(VariantId::EnumVariantId(variant)) = self.infer.as_ref()?.variant_resolution_for_expr(expr_id) { - return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); + return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); } } @@ -242,7 +242,7 @@ impl SourceAnalyzer { if let Some(VariantId::EnumVariantId(variant)) = self.infer.as_ref()?.variant_resolution_for_pat(pat_id) { - return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); + return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); } } @@ -251,7 +251,7 @@ impl SourceAnalyzer { if let Some(VariantId::EnumVariantId(variant)) = self.infer.as_ref()?.variant_resolution_for_expr(expr_id) { - return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); + return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); } } @@ -260,7 +260,7 @@ impl SourceAnalyzer { if let Some(VariantId::EnumVariantId(variant)) = self.infer.as_ref()?.variant_resolution_for_pat(pat_id) { - return Some(PathResolution::Def(ModuleDef::EnumVariant(variant.into()))); + return Some(PathResolution::Def(ModuleDef::Variant(variant.into()))); } } @@ -459,7 +459,7 @@ pub(crate) fn resolve_hir_path( TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { PathResolution::Def(Adt::from(it).into()) } - TypeNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), + TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), @@ -477,7 +477,7 @@ pub(crate) fn resolve_hir_path( ValueNs::ConstId(it) => PathResolution::Def(Const::from(it).into()), ValueNs::StaticId(it) => PathResolution::Def(Static::from(it).into()), ValueNs::StructId(it) => PathResolution::Def(Struct::from(it).into()), - ValueNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), + ValueNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), ValueNs::ImplSelf(impl_id) => PathResolution::SelfType(impl_id.into()), }; Some(res) @@ -526,7 +526,7 @@ fn resolve_hir_path_qualifier( TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()), - TypeNs::EnumVariantId(it) => PathResolution::Def(EnumVariant::from(it).into()), + TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), TypeNs::BuiltinType(it) => PathResolution::Def(it.into()), TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), -- cgit v1.2.3