From 45117c63884366ee82102a782a62a09fefff746b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Sep 2019 00:10:16 +0300 Subject: [PATCH] make various enums "inherit" from AdtDef --- crates/ra_hir/src/adt.rs | 22 +------ crates/ra_hir/src/code_model.rs | 61 +++++++++++++++++-- crates/ra_hir/src/expr/validation.rs | 3 +- crates/ra_hir/src/generics.rs | 49 +++++++-------- crates/ra_hir/src/lang_item.rs | 10 ++- crates/ra_hir/src/lib.rs | 4 +- crates/ra_hir/src/nameres.rs | 5 +- crates/ra_hir/src/nameres/collector.rs | 6 +- crates/ra_hir/src/resolve.rs | 6 +- crates/ra_hir/src/ty/infer.rs | 6 +- crates/ra_hir/src/ty/lower.rs | 58 +++++++++--------- .../src/completion/complete_path.rs | 13 ++-- .../src/completion/complete_pattern.rs | 2 +- .../ra_ide_api/src/completion/presentation.rs | 12 +++- .../src/display/navigation_target.rs | 4 +- crates/ra_ide_api/src/hover.rs | 12 ++-- crates/ra_ide_api/src/syntax_highlighting.rs | 4 +- 17 files changed, 156 insertions(+), 121 deletions(-) diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 728046b0d4..56f2b7aa36 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -9,29 +9,9 @@ use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, type_ref::TypeRef, - AsName, Crate, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField, - Union, + AsName, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField, }; -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum AdtDef { - Struct(Struct), - Union(Union), - Enum(Enum), -} -impl_froms!(AdtDef: Struct, Union, Enum); - -impl AdtDef { - pub(crate) fn krate(self, db: &impl HirDatabase) -> Option { - match self { - AdtDef::Struct(s) => s.module(db), - AdtDef::Union(s) => s.module(db), - AdtDef::Enum(e) => e.module(db), - } - .krate(db) - } -} - impl Struct { pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc { db.struct_data(self).variant_data.clone() diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 2bac6122bd..026753c9f6 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -127,9 +127,7 @@ impl BuiltinType { pub enum ModuleDef { Module(Module), Function(Function), - Struct(Struct), - Union(Union), - Enum(Enum), + AdtDef(AdtDef), // Can't be directly declared, but can be imported. EnumVariant(EnumVariant), Const(Const), @@ -141,9 +139,7 @@ pub enum ModuleDef { impl_froms!( ModuleDef: Module, Function, - Struct, - Union, - Enum, + AdtDef, EnumVariant, Const, Static, @@ -152,6 +148,24 @@ impl_froms!( BuiltinType ); +impl From for ModuleDef { + fn from(it: Struct) -> ModuleDef { + ModuleDef::AdtDef(AdtDef::Struct(it)) + } +} + +impl From for ModuleDef { + fn from(it: Enum) -> ModuleDef { + ModuleDef::AdtDef(AdtDef::Enum(it)) + } +} + +impl From for ModuleDef { + fn from(it: Union) -> ModuleDef { + ModuleDef::AdtDef(AdtDef::Union(it)) + } +} + pub enum ModuleSource { SourceFile(ast::SourceFile), Module(ast::Module), @@ -500,6 +514,41 @@ impl EnumVariant { } } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum AdtDef { + Struct(Struct), + Union(Union), + Enum(Enum), +} +impl_froms!(AdtDef: Struct, Union, Enum); + +impl AdtDef { + pub fn ty(self, db: &impl HirDatabase) -> Ty { + match self { + AdtDef::Struct(it) => it.ty(db), + AdtDef::Union(it) => it.ty(db), + AdtDef::Enum(it) => it.ty(db), + } + } + + pub(crate) fn krate(self, db: &impl HirDatabase) -> Option { + match self { + AdtDef::Struct(s) => s.module(db), + AdtDef::Union(s) => s.module(db), + AdtDef::Enum(e) => e.module(db), + } + .krate(db) + } + + pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { + match self { + AdtDef::Struct(it) => it.resolver(db), + AdtDef::Union(it) => it.resolver(db), + AdtDef::Enum(it) => it.resolver(db), + } + } +} + /// The defs which have a body. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DefWithBody { diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index c985dbdadf..447b9264a4 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -4,14 +4,13 @@ use ra_syntax::ast; use rustc_hash::FxHashSet; use crate::{ - adt::AdtDef, db::HirDatabase, diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, expr::AstPtr, name, path::{PathKind, PathSegment}, ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, - Function, Name, Path, + AdtDef, Function, Name, Path, }; use super::{Expr, ExprId, RecordLitField}; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index c76df0698c..0e89941f34 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -47,9 +47,7 @@ pub struct WherePredicate { #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub enum GenericDef { Function(Function), - Struct(Struct), - Union(Union), - Enum(Enum), + AdtDef(AdtDef), Trait(Trait), TypeAlias(TypeAlias), ImplBlock(ImplBlock), @@ -57,7 +55,25 @@ pub enum GenericDef { // can, and this makes some code easier to write EnumVariant(EnumVariant), } -impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, EnumVariant); +impl_froms!(GenericDef: Function, AdtDef, Trait, TypeAlias, ImplBlock, EnumVariant); + +impl From for GenericDef { + fn from(it: Struct) -> GenericDef { + GenericDef::AdtDef(AdtDef::Struct(it)) + } +} + +impl From for GenericDef { + fn from(it: Enum) -> GenericDef { + GenericDef::AdtDef(AdtDef::Enum(it)) + } +} + +impl From for GenericDef { + fn from(it: Union) -> GenericDef { + GenericDef::AdtDef(AdtDef::Union(it)) + } +} impl GenericParams { pub(crate) fn generic_params_query( @@ -69,10 +85,7 @@ impl GenericParams { GenericDef::Function(it) => it.container(db).map(GenericDef::from), GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), - GenericDef::Struct(_) - | GenericDef::Union(_) - | GenericDef::Enum(_) - | GenericDef::Trait(_) => None, + GenericDef::AdtDef(_) | GenericDef::Trait(_) => None, GenericDef::ImplBlock(_) => None, }; generics.parent_params = parent.map(|p| db.generic_params(p)); @@ -80,9 +93,9 @@ impl GenericParams { // FIXME: add `: Sized` bound for everything except for `Self` in traits match def { GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), - GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start), - GenericDef::Union(it) => generics.fill(&it.source(db).ast, start), - GenericDef::Enum(it) => generics.fill(&it.source(db).ast, start), + GenericDef::AdtDef(AdtDef::Struct(it)) => generics.fill(&it.source(db).ast, start), + GenericDef::AdtDef(AdtDef::Union(it)) => generics.fill(&it.source(db).ast, start), + GenericDef::AdtDef(AdtDef::Enum(it)) => generics.fill(&it.source(db).ast, start), GenericDef::Trait(it) => { // traits get the Self type as an implicit first type parameter generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); @@ -186,9 +199,7 @@ impl GenericDef { pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { match self { GenericDef::Function(inner) => inner.resolver(db), - GenericDef::Struct(inner) => inner.resolver(db), - GenericDef::Union(inner) => inner.resolver(db), - GenericDef::Enum(inner) => inner.resolver(db), + GenericDef::AdtDef(adt) => adt.resolver(db), GenericDef::Trait(inner) => inner.resolver(db), GenericDef::TypeAlias(inner) => inner.resolver(db), GenericDef::ImplBlock(inner) => inner.resolver(db), @@ -206,16 +217,6 @@ impl From for GenericDef { } } -impl From for GenericDef { - fn from(adt: crate::adt::AdtDef) -> Self { - match adt { - AdtDef::Struct(s) => s.into(), - AdtDef::Union(u) => u.into(), - AdtDef::Enum(e) => e.into(), - } - } -} - pub trait HasGenericParams: Copy { fn generic_params(self, db: &impl DefDatabase) -> Arc; } diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 832fdf1f57..87484d8926 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs @@ -5,7 +5,7 @@ use ra_syntax::{ast::AttrsOwner, SmolStr}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, + AdtDef, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -107,8 +107,12 @@ impl LangItems { ModuleDef::Trait(trait_) => { self.collect_lang_item(db, trait_, LangItemTarget::Trait) } - ModuleDef::Enum(e) => self.collect_lang_item(db, e, LangItemTarget::Enum), - ModuleDef::Struct(s) => self.collect_lang_item(db, s, LangItemTarget::Struct), + ModuleDef::AdtDef(AdtDef::Enum(e)) => { + self.collect_lang_item(db, e, LangItemTarget::Enum) + } + ModuleDef::AdtDef(AdtDef::Struct(s)) => { + self.collect_lang_item(db, s, LangItemTarget::Struct) + } ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static), _ => {} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 24ee84f86a..2fe1a658ee 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -57,7 +57,7 @@ use crate::{ }; pub use self::{ - adt::{AdtDef, VariantDef}, + adt::VariantDef, either::Either, expr::ExprScopes, generics::{GenericParam, GenericParams, HasGenericParams}, @@ -78,7 +78,7 @@ pub use self::{ pub use self::code_model::{ docs::{DocDef, Docs, Documentation}, src::{HasBodySource, HasSource, Source}, - BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, + AdtDef, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 3d8691f535..1efaad4bc4 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -69,7 +69,8 @@ use crate::{ diagnostics::DiagnosticSink, ids::MacroDefId, nameres::diagnostics::DefDiagnostic, - AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, + AdtDef, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, + PathKind, Trait, }; pub(crate) use self::raw::{ImportSourceMap, RawItems}; @@ -425,7 +426,7 @@ impl CrateDefMap { } } } - ModuleDef::Enum(e) => { + ModuleDef::AdtDef(AdtDef::Enum(e)) => { // enum variant tested_by!(can_import_enum_variant); match e.variant(db, &segment.name) { diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 03fbbd33f8..ced1ebf1eb 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -13,8 +13,8 @@ use crate::{ raw, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, - AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, - Struct, Trait, TypeAlias, Union, + AdtDef, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, + Static, Struct, Trait, TypeAlias, Union, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -314,7 +314,7 @@ where .push((module_id, import_id)); } } - Some(ModuleDef::Enum(e)) => { + Some(ModuleDef::AdtDef(AdtDef::Enum(e))) => { tested_by!(glob_enum); // glob import from enum => just import all the variants let variants = e.variants(self.db); diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 1ed150f5a3..2519451124 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -15,7 +15,7 @@ use crate::{ name::{Name, SELF_PARAM, SELF_TYPE}, nameres::{CrateDefMap, CrateModuleId, PerNs}, path::Path, - Enum, MacroDef, ModuleDef, Struct, Trait, + AdtDef, Enum, MacroDef, ModuleDef, Struct, Trait, }; #[derive(Debug, Clone, Default)] @@ -143,7 +143,7 @@ impl Resolver { ) -> Option { let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; match res { - Resolution::Def(ModuleDef::Struct(it)) => Some(it), + Resolution::Def(ModuleDef::AdtDef(AdtDef::Struct(it))) => Some(it), _ => None, } } @@ -152,7 +152,7 @@ impl Resolver { pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option { let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; match res { - Resolution::Def(ModuleDef::Enum(it)) => Some(it), + Resolution::Def(ModuleDef::AdtDef(AdtDef::Enum(it))) => Some(it), _ => None, } } diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 3970c49e32..725eec8340 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -668,7 +668,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // FIXME remove the duplication between here and `Ty::from_path`? let substs = Ty::substs_from_path(self.db, resolver, path, def); match def { - TypableDef::Struct(s) => { + TypableDef::AdtDef(AdtDef::Struct(s)) => { let ty = s.ty(self.db); let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(s.into())) @@ -678,10 +678,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let ty = self.insert_type_vars(ty.apply_substs(substs)); (ty, Some(var.into())) } - TypableDef::Union(_) + TypableDef::AdtDef(AdtDef::Enum(_)) + | TypableDef::AdtDef(AdtDef::Union(_)) | TypableDef::TypeAlias(_) | TypableDef::Function(_) - | TypableDef::Enum(_) | TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => (Ty::Unknown, None), diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index e67525a748..587dc12ee8 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -172,9 +172,7 @@ impl Ty { ) -> Substs { let def_generic: Option = match resolved { TypableDef::Function(func) => Some(func.into()), - TypableDef::Struct(s) => Some(s.into()), - TypableDef::Union(u) => Some(u.into()), - TypableDef::Enum(e) => Some(e.into()), + TypableDef::AdtDef(adt) => Some(adt.into()), TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), TypableDef::TypeAlias(t) => Some(t.into()), TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, @@ -193,9 +191,7 @@ impl Ty { let last = path.segments.last().expect("path should have at least one segment"); let segment = match resolved { TypableDef::Function(_) - | TypableDef::Struct(_) - | TypableDef::Union(_) - | TypableDef::Enum(_) + | TypableDef::AdtDef(_) | TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::TypeAlias(_) @@ -410,11 +406,11 @@ fn assoc_type_bindings_from_type_bound<'a>( pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty { match (def, ns) { (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f), - (TypableDef::Struct(s), Namespace::Types) => type_for_adt(db, s), - (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), - (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), + (TypableDef::AdtDef(AdtDef::Struct(s)), Namespace::Values) => { + type_for_struct_constructor(db, s) + } + (TypableDef::AdtDef(adt), Namespace::Types) => type_for_adt(db, adt), (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), - (TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u), (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), @@ -422,8 +418,8 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace // 'error' cases: (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, - (TypableDef::Union(_), Namespace::Values) => Ty::Unknown, - (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, + (TypableDef::AdtDef(AdtDef::Union(_)), Namespace::Values) => Ty::Unknown, + (TypableDef::AdtDef(AdtDef::Enum(_)), Namespace::Values) => Ty::Unknown, (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, @@ -608,34 +604,38 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum TypableDef { Function(Function), - Struct(Struct), - Union(Union), - Enum(Enum), + AdtDef(AdtDef), EnumVariant(EnumVariant), TypeAlias(TypeAlias), Const(Const), Static(Static), BuiltinType(BuiltinType), } -impl_froms!( - TypableDef: Function, - Struct, - Union, - Enum, - EnumVariant, - TypeAlias, - Const, - Static, - BuiltinType -); +impl_froms!(TypableDef: Function, AdtDef, EnumVariant, TypeAlias, Const, Static, BuiltinType); + +impl From for TypableDef { + fn from(it: Struct) -> TypableDef { + TypableDef::AdtDef(AdtDef::Struct(it)) + } +} + +impl From for TypableDef { + fn from(it: Enum) -> TypableDef { + TypableDef::AdtDef(AdtDef::Enum(it)) + } +} + +impl From for TypableDef { + fn from(it: Union) -> TypableDef { + TypableDef::AdtDef(AdtDef::Union(it)) + } +} impl From for Option { fn from(def: ModuleDef) -> Option { let res = match def { ModuleDef::Function(f) => f.into(), - ModuleDef::Struct(s) => s.into(), - ModuleDef::Union(u) => u.into(), - ModuleDef::Enum(e) => e.into(), + ModuleDef::AdtDef(adt) => adt.into(), ModuleDef::EnumVariant(v) => v.into(), ModuleDef::TypeAlias(t) => t.into(), ModuleDef::Const(v) => v.into(), diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 457a3d10c7..df14f465a1 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,4 +1,4 @@ -use hir::{Either, Resolution}; +use hir::{AdtDef, Either, Resolution}; use ra_syntax::AstNode; use test_utils::tested_by; @@ -37,19 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); } } - hir::ModuleDef::Enum(_) - | hir::ModuleDef::Struct(_) - | hir::ModuleDef::Union(_) - | hir::ModuleDef::TypeAlias(_) => { - if let hir::ModuleDef::Enum(e) = def { + hir::ModuleDef::AdtDef(_) | hir::ModuleDef::TypeAlias(_) => { + if let hir::ModuleDef::AdtDef(AdtDef::Enum(e)) = def { for variant in e.variants(ctx.db) { acc.add_enum_variant(ctx, variant); } } let ty = match def { - hir::ModuleDef::Enum(e) => e.ty(ctx.db), - hir::ModuleDef::Struct(s) => s.ty(ctx.db), - hir::ModuleDef::Union(u) => u.ty(ctx.db), + hir::ModuleDef::AdtDef(adt) => adt.ty(ctx.db), hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), _ => unreachable!(), }; diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index fb02844fad..05db973e40 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -15,7 +15,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { _ => continue, }; match def { - hir::ModuleDef::Enum(..) + hir::ModuleDef::AdtDef(hir::AdtDef::Enum(..)) | hir::ModuleDef::EnumVariant(..) | hir::ModuleDef::Const(..) | hir::ModuleDef::Module(..) => (), diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 5cabe9a321..e9bf2b96d9 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -67,9 +67,15 @@ impl Completions { Resolution::Def(Function(func)) => { return self.add_function_with_name(ctx, Some(local_name), *func); } - Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), - Resolution::Def(Union(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), - Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), + Resolution::Def(AdtDef(hir::AdtDef::Struct(it))) => { + (CompletionItemKind::Struct, it.docs(ctx.db)) + } + Resolution::Def(AdtDef(hir::AdtDef::Union(it))) => { + (CompletionItemKind::Struct, it.docs(ctx.db)) + } + Resolution::Def(AdtDef(hir::AdtDef::Enum(it))) => { + (CompletionItemKind::Enum, it.docs(ctx.db)) + } Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index c85214bb35..b8085f0772 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -193,9 +193,7 @@ impl NavigationTarget { let nav = match module_def { hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), - hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), - hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), - hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), + hir::ModuleDef::AdtDef(it) => NavigationTarget::from_adt_def(db, it), hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 4b7847de85..f7b7cb8f8d 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -1,4 +1,4 @@ -use hir::{HasSource, HirDisplay}; +use hir::{AdtDef, HasSource, HirDisplay}; use ra_db::SourceDatabase; use ra_syntax::{ algo::{ @@ -129,9 +129,13 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option res.extend(from_def_source(db, it)), - hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::AdtDef(AdtDef::Struct(it)) => { + res.extend(from_def_source(db, it)) + } + hir::ModuleDef::AdtDef(AdtDef::Union(it)) => { + res.extend(from_def_source(db, it)) + } + hir::ModuleDef::AdtDef(AdtDef::Enum(it)) => res.extend(from_def_source(db, it)), hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 06ccf07286..ee7531d37d 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -107,9 +107,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec "type", Some(Def(hir::ModuleDef::Module(_))) => "module", Some(Def(hir::ModuleDef::Function(_))) => "function", - Some(Def(hir::ModuleDef::Struct(_))) => "type", - Some(Def(hir::ModuleDef::Union(_))) => "type", - Some(Def(hir::ModuleDef::Enum(_))) => "type", + Some(Def(hir::ModuleDef::AdtDef(_))) => "type", Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", Some(Def(hir::ModuleDef::Const(_))) => "constant", Some(Def(hir::ModuleDef::Static(_))) => "constant",