diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 2e56bd7ffc0..030b9cd0c7d 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -1,7 +1,7 @@ use std::iter; use either::Either; -use hir::{AsName, EnumVariant, Module, ModuleDef, Name}; +use hir::{AsName, Module, ModuleDef, Name, Variant}; use ide_db::helpers::{ insert_use::{insert_use, ImportScope}, mod_path_to_ast, @@ -53,7 +53,7 @@ pub(crate) fn extract_struct_from_enum_variant( let variant_hir_name = variant_hir.name(ctx.db()); let enum_module_def = ModuleDef::from(enum_hir); let usages = - Definition::ModuleDef(ModuleDef::EnumVariant(variant_hir)).usages(&ctx.sema).all(); + Definition::ModuleDef(ModuleDef::Variant(variant_hir)).usages(&ctx.sema).all(); let mut visited_modules_set = FxHashSet::default(); let current_module = enum_hir.module(ctx.db()); @@ -109,7 +109,7 @@ fn extract_field_list_if_applicable( } } -fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &EnumVariant) -> bool { +fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &Variant) -> bool { variant .parent_enum(db) .module(db) @@ -119,7 +119,7 @@ fn existing_definition(db: &RootDatabase, variant_name: &ast::Name, variant: &En // only check type-namespace hir::ScopeDef::ModuleDef(def) => matches!(def, ModuleDef::Module(_) | ModuleDef::Adt(_) | - ModuleDef::EnumVariant(_) | ModuleDef::Trait(_) | + ModuleDef::Variant(_) | ModuleDef::Trait(_) | ModuleDef::TypeAlias(_) | ModuleDef::BuiltinType(_) ), _ => false, diff --git a/crates/assists/src/handlers/fill_match_arms.rs b/crates/assists/src/handlers/fill_match_arms.rs index ef12ef0cf1a..cb60a312828 100644 --- a/crates/assists/src/handlers/fill_match_arms.rs +++ b/crates/assists/src/handlers/fill_match_arms.rs @@ -192,7 +192,7 @@ fn resolve_tuple_of_enum_def( .collect() } -fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> Option { +fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::Variant) -> Option { let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?); // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index c867207877b..8558a8ff01c 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs @@ -201,7 +201,7 @@ fn target_data_for_def( (vis_offset(syntax), in_file_source.value.visibility(), syntax.text_range(), file_id) } // Enum variants can't be private, we can't modify builtin types - hir::ModuleDef::EnumVariant(_) | hir::ModuleDef::BuiltinType(_) => return None, + hir::ModuleDef::Variant(_) | hir::ModuleDef::BuiltinType(_) => return None, }; Some((offset, current_visibility, target, target_file, target_name)) diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs index 9b7d6c58091..1ef6b5f48f1 100644 --- a/crates/completion/src/completions.rs +++ b/crates/completion/src/completions.rs @@ -19,7 +19,7 @@ use hir::{ModPath, ScopeDef, Type}; use crate::{ item::Builder, render::{ - const_::render_const, enum_variant::render_enum_variant, function::render_fn, + const_::render_const, enum_variant::render_variant, function::render_fn, macro_::render_macro, render_field, render_resolution, render_tuple_field, type_alias::render_type_alias, RenderContext, }, @@ -120,20 +120,20 @@ impl Completions { pub(crate) fn add_qualified_enum_variant( &mut self, ctx: &CompletionContext, - variant: hir::EnumVariant, + variant: hir::Variant, path: ModPath, ) { - let item = render_enum_variant(RenderContext::new(ctx), None, None, variant, Some(path)); + let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); self.add(item); } pub(crate) fn add_enum_variant( &mut self, ctx: &CompletionContext, - variant: hir::EnumVariant, + variant: hir::Variant, local_name: Option, ) { - let item = render_enum_variant(RenderContext::new(ctx), None, local_name, variant, None); + let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); self.add(item); } } diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs index 0c98e4412e7..4d56731ec61 100644 --- a/crates/completion/src/completions/pattern.rs +++ b/crates/completion/src/completions/pattern.rs @@ -23,7 +23,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { def, hir::ModuleDef::Adt(hir::Adt::Enum(..)) | hir::ModuleDef::Adt(hir::Adt::Struct(..)) - | hir::ModuleDef::EnumVariant(..) + | hir::ModuleDef::Variant(..) | hir::ModuleDef::Const(..) | hir::ModuleDef::Module(..) ) diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index b940388df26..1092a482561 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -19,7 +19,7 @@ use crate::{ CompletionKind, CompletionScore, }; -use crate::render::{enum_variant::render_enum_variant, function::render_fn, macro_::render_macro}; +use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro}; pub(crate) fn render_field<'a>( ctx: RenderContext<'a>, @@ -159,9 +159,8 @@ impl<'a> Render<'a> { let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); return Some(item); } - ScopeDef::ModuleDef(EnumVariant(var)) => { - let item = - render_enum_variant(self.ctx, import_to_add, Some(local_name), *var, None); + ScopeDef::ModuleDef(Variant(var)) => { + let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None); return Some(item); } ScopeDef::MacroDef(mac) => { @@ -257,7 +256,7 @@ impl<'a> Render<'a> { match resolution { ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()), - ScopeDef::ModuleDef(EnumVariant(it)) => it.docs(self.ctx.db()), + ScopeDef::ModuleDef(Variant(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()), ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()), diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 8e0fea6c0fc..7176fd9b3d1 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs @@ -9,35 +9,35 @@ use crate::{ render::{builder_ext::Params, RenderContext}, }; -pub(crate) fn render_enum_variant<'a>( +pub(crate) fn render_variant<'a>( ctx: RenderContext<'a>, import_to_add: Option, local_name: Option, - variant: hir::EnumVariant, + variant: hir::Variant, path: Option, ) -> CompletionItem { let _p = profile::span("render_enum_variant"); - EnumVariantRender::new(ctx, local_name, variant, path).render(import_to_add) + EnumRender::new(ctx, local_name, variant, path).render(import_to_add) } #[derive(Debug)] -struct EnumVariantRender<'a> { +struct EnumRender<'a> { ctx: RenderContext<'a>, name: String, - variant: hir::EnumVariant, + variant: hir::Variant, path: Option, qualified_name: String, short_qualified_name: String, variant_kind: StructKind, } -impl<'a> EnumVariantRender<'a> { +impl<'a> EnumRender<'a> { fn new( ctx: RenderContext<'a>, local_name: Option, - variant: hir::EnumVariant, + variant: hir::Variant, path: Option, - ) -> EnumVariantRender<'a> { + ) -> EnumRender<'a> { let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string()); let variant_kind = variant.kind(ctx.db()); @@ -51,15 +51,7 @@ impl<'a> EnumVariantRender<'a> { None => (name.to_string(), name.to_string()), }; - EnumVariantRender { - ctx, - name, - variant, - path, - qualified_name, - short_qualified_name, - variant_kind, - } + EnumRender { ctx, name, variant, path, qualified_name, short_qualified_name, variant_kind } } fn render(self, import_to_add: Option) -> CompletionItem { diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 1f2ee258001..d32ce37edb2 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 3248f6d201a..d6c7e71ea5a 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 8d0f84508d2..8e0c571b851 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 c5b81b2524b..0dc07c33e22 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 3f4f8d8e4af..bdd270c58d3 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 83ec91f587f..25ebf73d88e 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 bf0c959feef..bddc49c05a8 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()), diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 13240672f0b..e8b89662385 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs @@ -166,7 +166,7 @@ fn missing_record_expr_field_fix( def_file_id = source.file_id; source.value.record_field_list()? } - VariantDef::EnumVariant(e) => { + VariantDef::Variant(e) => { module = e.module(sema.db); let source = e.source(sema.db); def_file_id = source.file_id; diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 7d0514105bc..cd8ec54fa72 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -233,7 +233,7 @@ impl TryToNav for hir::ModuleDef { hir::ModuleDef::Module(it) => it.to_nav(db), hir::ModuleDef::Function(it) => it.to_nav(db), hir::ModuleDef::Adt(it) => it.to_nav(db), - hir::ModuleDef::EnumVariant(it) => it.to_nav(db), + hir::ModuleDef::Variant(it) => it.to_nav(db), hir::ModuleDef::Const(it) => it.to_nav(db), hir::ModuleDef::Static(it) => it.to_nav(db), hir::ModuleDef::Trait(it) => it.to_nav(db), @@ -262,7 +262,7 @@ impl ToNavFromAst for hir::Struct { impl ToNavFromAst for hir::Enum { const KIND: SymbolKind = SymbolKind::Enum; } -impl ToNavFromAst for hir::EnumVariant { +impl ToNavFromAst for hir::Variant { const KIND: SymbolKind = SymbolKind::Variant; } impl ToNavFromAst for hir::Union { diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 79c081cac26..b61ea0b3e40 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -181,7 +181,7 @@ fn rewrite_intra_doc_link( ModuleDef::Module(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Function(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Adt(it) => it.resolve_doc_path(db, link, ns), - ModuleDef::EnumVariant(it) => it.resolve_doc_path(db, link, ns), + ModuleDef::Variant(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Const(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Static(it) => it.resolve_doc_path(db, link, ns), ModuleDef::Trait(it) => it.resolve_doc_path(db, link, ns), @@ -390,7 +390,7 @@ fn get_symbol_filename(db: &dyn HirDatabase, definition: &ModuleDef) -> Option format!("type.{}.html", t.name(db)), ModuleDef::BuiltinType(t) => format!("primitive.{}.html", t.as_name()), ModuleDef::Function(f) => format!("fn.{}.html", f.name(db)), - ModuleDef::EnumVariant(ev) => { + ModuleDef::Variant(ev) => { format!("enum.{}.html#variant.{}", ev.parent_enum(db).name(db), ev.name(db)) } ModuleDef::Const(c) => format!("const.{}.html", c.name(db)?), diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index b06fa5f1557..52f993cc92b 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -297,7 +297,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option AssocItemContainer::Trait(t) => Some(t.name(db)), AssocItemContainer::Impl(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)), }, - ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)), + ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)), _ => None, }, _ => None, @@ -355,7 +355,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option { ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path), - ModuleDef::EnumVariant(it) => from_def_source(db, it, mod_path), + ModuleDef::Variant(it) => from_def_source(db, it, mod_path), ModuleDef::Const(it) => from_def_source(db, it, mod_path), ModuleDef::Static(it) => from_def_source(db, it, mod_path), ModuleDef::Trait(it) => from_def_source(db, it, mod_path), diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index ff386be8049..2f2b99130e3 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -167,7 +167,7 @@ fn module_def_doctest(sema: &Semantics, def: hir::ModuleDef) -> Op hir::ModuleDef::Module(it) => it.attrs(sema.db), hir::ModuleDef::Function(it) => it.attrs(sema.db), hir::ModuleDef::Adt(it) => it.attrs(sema.db), - hir::ModuleDef::EnumVariant(it) => it.attrs(sema.db), + hir::ModuleDef::Variant(it) => it.attrs(sema.db), hir::ModuleDef::Const(it) => it.attrs(sema.db), hir::ModuleDef::Static(it) => it.attrs(sema.db), hir::ModuleDef::Trait(it) => it.attrs(sema.db), diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 67ad7c63ddf..00c717c7c7e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -781,7 +781,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Symbol(SymbolKind::Struct), hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Symbol(SymbolKind::Enum), hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Symbol(SymbolKind::Union), - hir::ModuleDef::EnumVariant(_) => HighlightTag::Symbol(SymbolKind::Variant), + hir::ModuleDef::Variant(_) => HighlightTag::Symbol(SymbolKind::Variant), hir::ModuleDef::Const(konst) => { let mut h = Highlight::new(HighlightTag::Symbol(SymbolKind::Const)); if konst.as_assoc_item(db).is_some() { diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index bd2afc88760..9d7dce1d47d 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -66,7 +66,7 @@ impl Definition { hir::Adt::Union(it) => it.name(db), hir::Adt::Enum(it) => it.name(db), }, - hir::ModuleDef::EnumVariant(it) => it.name(db), + hir::ModuleDef::Variant(it) => it.name(db), hir::ModuleDef::Const(it) => it.name(db)?, hir::ModuleDef::Static(it) => it.name(db)?, hir::ModuleDef::Trait(it) => it.name(db), @@ -207,7 +207,7 @@ impl NameClass { Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, ast::Variant(it) => { - let def: hir::EnumVariant = sema.to_def(&it)?; + let def: hir::Variant = sema.to_def(&it)?; Some(NameClass::Definition(Definition::ModuleDef(def.into()))) }, ast::Fn(it) => { diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 525c8a41fed..ff10f71c358 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -141,7 +141,7 @@ impl Definition { hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(), - hir::GenericDef::EnumVariant(it) => it.source(db).value.syntax().text_range(), + hir::GenericDef::Variant(it) => it.source(db).value.syntax().text_range(), hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(), }; let mut res = FxHashMap::default();