aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-12 22:10:16 +0100
committerAleksey Kladov <[email protected]>2019-09-12 22:10:16 +0100
commit45117c63884366ee82102a782a62a09fefff746b (patch)
treeb66d9ca105e39b96b78bf7f3659d1858577a2c8c /crates/ra_hir
parentd8b621cf26b59ff5ae9379b50fc822590b6a3a4e (diff)
make various enums "inherit" from AdtDef
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs22
-rw-r--r--crates/ra_hir/src/code_model.rs61
-rw-r--r--crates/ra_hir/src/expr/validation.rs3
-rw-r--r--crates/ra_hir/src/generics.rs49
-rw-r--r--crates/ra_hir/src/lang_item.rs10
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/nameres.rs5
-rw-r--r--crates/ra_hir/src/nameres/collector.rs6
-rw-r--r--crates/ra_hir/src/resolve.rs6
-rw-r--r--crates/ra_hir/src/ty/infer.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs58
11 files changed, 132 insertions, 98 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 728046b0d..56f2b7aa3 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};
9use crate::{ 9use crate::{
10 db::{AstDatabase, DefDatabase, HirDatabase}, 10 db::{AstDatabase, DefDatabase, HirDatabase},
11 type_ref::TypeRef, 11 type_ref::TypeRef,
12 AsName, Crate, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField, 12 AsName, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField,
13 Union,
14}; 13};
15 14
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
17pub enum AdtDef {
18 Struct(Struct),
19 Union(Union),
20 Enum(Enum),
21}
22impl_froms!(AdtDef: Struct, Union, Enum);
23
24impl AdtDef {
25 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
26 match self {
27 AdtDef::Struct(s) => s.module(db),
28 AdtDef::Union(s) => s.module(db),
29 AdtDef::Enum(e) => e.module(db),
30 }
31 .krate(db)
32 }
33}
34
35impl Struct { 15impl Struct {
36 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { 16 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
37 db.struct_data(self).variant_data.clone() 17 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 2bac6122b..026753c9f 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -127,9 +127,7 @@ impl BuiltinType {
127pub enum ModuleDef { 127pub enum ModuleDef {
128 Module(Module), 128 Module(Module),
129 Function(Function), 129 Function(Function),
130 Struct(Struct), 130 AdtDef(AdtDef),
131 Union(Union),
132 Enum(Enum),
133 // Can't be directly declared, but can be imported. 131 // Can't be directly declared, but can be imported.
134 EnumVariant(EnumVariant), 132 EnumVariant(EnumVariant),
135 Const(Const), 133 Const(Const),
@@ -141,9 +139,7 @@ pub enum ModuleDef {
141impl_froms!( 139impl_froms!(
142 ModuleDef: Module, 140 ModuleDef: Module,
143 Function, 141 Function,
144 Struct, 142 AdtDef,
145 Union,
146 Enum,
147 EnumVariant, 143 EnumVariant,
148 Const, 144 Const,
149 Static, 145 Static,
@@ -152,6 +148,24 @@ impl_froms!(
152 BuiltinType 148 BuiltinType
153); 149);
154 150
151impl From<Struct> for ModuleDef {
152 fn from(it: Struct) -> ModuleDef {
153 ModuleDef::AdtDef(AdtDef::Struct(it))
154 }
155}
156
157impl From<Enum> for ModuleDef {
158 fn from(it: Enum) -> ModuleDef {
159 ModuleDef::AdtDef(AdtDef::Enum(it))
160 }
161}
162
163impl From<Union> for ModuleDef {
164 fn from(it: Union) -> ModuleDef {
165 ModuleDef::AdtDef(AdtDef::Union(it))
166 }
167}
168
155pub enum ModuleSource { 169pub enum ModuleSource {
156 SourceFile(ast::SourceFile), 170 SourceFile(ast::SourceFile),
157 Module(ast::Module), 171 Module(ast::Module),
@@ -500,6 +514,41 @@ impl EnumVariant {
500 } 514 }
501} 515}
502 516
517#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
518pub enum AdtDef {
519 Struct(Struct),
520 Union(Union),
521 Enum(Enum),
522}
523impl_froms!(AdtDef: Struct, Union, Enum);
524
525impl AdtDef {
526 pub fn ty(self, db: &impl HirDatabase) -> Ty {
527 match self {
528 AdtDef::Struct(it) => it.ty(db),
529 AdtDef::Union(it) => it.ty(db),
530 AdtDef::Enum(it) => it.ty(db),
531 }
532 }
533
534 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
535 match self {
536 AdtDef::Struct(s) => s.module(db),
537 AdtDef::Union(s) => s.module(db),
538 AdtDef::Enum(e) => e.module(db),
539 }
540 .krate(db)
541 }
542
543 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
544 match self {
545 AdtDef::Struct(it) => it.resolver(db),
546 AdtDef::Union(it) => it.resolver(db),
547 AdtDef::Enum(it) => it.resolver(db),
548 }
549 }
550}
551
503/// The defs which have a body. 552/// The defs which have a body.
504#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 553#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
505pub enum DefWithBody { 554pub enum DefWithBody {
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index c985dbdad..447b9264a 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;
4use rustc_hash::FxHashSet; 4use rustc_hash::FxHashSet;
5 5
6use crate::{ 6use crate::{
7 adt::AdtDef,
8 db::HirDatabase, 7 db::HirDatabase,
9 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, 8 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr},
10 expr::AstPtr, 9 expr::AstPtr,
11 name, 10 name,
12 path::{PathKind, PathSegment}, 11 path::{PathKind, PathSegment},
13 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 12 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
14 Function, Name, Path, 13 AdtDef, Function, Name, Path,
15}; 14};
16 15
17use super::{Expr, ExprId, RecordLitField}; 16use super::{Expr, ExprId, RecordLitField};
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index c76df0698..0e89941f3 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -47,9 +47,7 @@ pub struct WherePredicate {
47#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 47#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
48pub enum GenericDef { 48pub enum GenericDef {
49 Function(Function), 49 Function(Function),
50 Struct(Struct), 50 AdtDef(AdtDef),
51 Union(Union),
52 Enum(Enum),
53 Trait(Trait), 51 Trait(Trait),
54 TypeAlias(TypeAlias), 52 TypeAlias(TypeAlias),
55 ImplBlock(ImplBlock), 53 ImplBlock(ImplBlock),
@@ -57,7 +55,25 @@ pub enum GenericDef {
57 // can, and this makes some code easier to write 55 // can, and this makes some code easier to write
58 EnumVariant(EnumVariant), 56 EnumVariant(EnumVariant),
59} 57}
60impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, EnumVariant); 58impl_froms!(GenericDef: Function, AdtDef, Trait, TypeAlias, ImplBlock, EnumVariant);
59
60impl From<Struct> for GenericDef {
61 fn from(it: Struct) -> GenericDef {
62 GenericDef::AdtDef(AdtDef::Struct(it))
63 }
64}
65
66impl From<Enum> for GenericDef {
67 fn from(it: Enum) -> GenericDef {
68 GenericDef::AdtDef(AdtDef::Enum(it))
69 }
70}
71
72impl From<Union> for GenericDef {
73 fn from(it: Union) -> GenericDef {
74 GenericDef::AdtDef(AdtDef::Union(it))
75 }
76}
61 77
62impl GenericParams { 78impl GenericParams {
63 pub(crate) fn generic_params_query( 79 pub(crate) fn generic_params_query(
@@ -69,10 +85,7 @@ impl GenericParams {
69 GenericDef::Function(it) => it.container(db).map(GenericDef::from), 85 GenericDef::Function(it) => it.container(db).map(GenericDef::from),
70 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), 86 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
71 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), 87 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
72 GenericDef::Struct(_) 88 GenericDef::AdtDef(_) | GenericDef::Trait(_) => None,
73 | GenericDef::Union(_)
74 | GenericDef::Enum(_)
75 | GenericDef::Trait(_) => None,
76 GenericDef::ImplBlock(_) => None, 89 GenericDef::ImplBlock(_) => None,
77 }; 90 };
78 generics.parent_params = parent.map(|p| db.generic_params(p)); 91 generics.parent_params = parent.map(|p| db.generic_params(p));
@@ -80,9 +93,9 @@ impl GenericParams {
80 // FIXME: add `: Sized` bound for everything except for `Self` in traits 93 // FIXME: add `: Sized` bound for everything except for `Self` in traits
81 match def { 94 match def {
82 GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), 95 GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
83 GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start), 96 GenericDef::AdtDef(AdtDef::Struct(it)) => generics.fill(&it.source(db).ast, start),
84 GenericDef::Union(it) => generics.fill(&it.source(db).ast, start), 97 GenericDef::AdtDef(AdtDef::Union(it)) => generics.fill(&it.source(db).ast, start),
85 GenericDef::Enum(it) => generics.fill(&it.source(db).ast, start), 98 GenericDef::AdtDef(AdtDef::Enum(it)) => generics.fill(&it.source(db).ast, start),
86 GenericDef::Trait(it) => { 99 GenericDef::Trait(it) => {
87 // traits get the Self type as an implicit first type parameter 100 // traits get the Self type as an implicit first type parameter
88 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); 101 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
@@ -186,9 +199,7 @@ impl GenericDef {
186 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { 199 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
187 match self { 200 match self {
188 GenericDef::Function(inner) => inner.resolver(db), 201 GenericDef::Function(inner) => inner.resolver(db),
189 GenericDef::Struct(inner) => inner.resolver(db), 202 GenericDef::AdtDef(adt) => adt.resolver(db),
190 GenericDef::Union(inner) => inner.resolver(db),
191 GenericDef::Enum(inner) => inner.resolver(db),
192 GenericDef::Trait(inner) => inner.resolver(db), 203 GenericDef::Trait(inner) => inner.resolver(db),
193 GenericDef::TypeAlias(inner) => inner.resolver(db), 204 GenericDef::TypeAlias(inner) => inner.resolver(db),
194 GenericDef::ImplBlock(inner) => inner.resolver(db), 205 GenericDef::ImplBlock(inner) => inner.resolver(db),
@@ -206,16 +217,6 @@ impl From<Container> for GenericDef {
206 } 217 }
207} 218}
208 219
209impl From<crate::adt::AdtDef> for GenericDef {
210 fn from(adt: crate::adt::AdtDef) -> Self {
211 match adt {
212 AdtDef::Struct(s) => s.into(),
213 AdtDef::Union(u) => u.into(),
214 AdtDef::Enum(e) => e.into(),
215 }
216 }
217}
218
219pub trait HasGenericParams: Copy { 220pub trait HasGenericParams: Copy {
220 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>; 221 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>;
221} 222}
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs
index 832fdf1f5..87484d892 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};
5 5
6use crate::{ 6use crate::{
7 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
8 Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, 8 AdtDef, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait,
9}; 9};
10 10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -107,8 +107,12 @@ impl LangItems {
107 ModuleDef::Trait(trait_) => { 107 ModuleDef::Trait(trait_) => {
108 self.collect_lang_item(db, trait_, LangItemTarget::Trait) 108 self.collect_lang_item(db, trait_, LangItemTarget::Trait)
109 } 109 }
110 ModuleDef::Enum(e) => self.collect_lang_item(db, e, LangItemTarget::Enum), 110 ModuleDef::AdtDef(AdtDef::Enum(e)) => {
111 ModuleDef::Struct(s) => self.collect_lang_item(db, s, LangItemTarget::Struct), 111 self.collect_lang_item(db, e, LangItemTarget::Enum)
112 }
113 ModuleDef::AdtDef(AdtDef::Struct(s)) => {
114 self.collect_lang_item(db, s, LangItemTarget::Struct)
115 }
112 ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), 116 ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function),
113 ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static), 117 ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static),
114 _ => {} 118 _ => {}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 24ee84f86..2fe1a658e 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -57,7 +57,7 @@ use crate::{
57}; 57};
58 58
59pub use self::{ 59pub use self::{
60 adt::{AdtDef, VariantDef}, 60 adt::VariantDef,
61 either::Either, 61 either::Either,
62 expr::ExprScopes, 62 expr::ExprScopes,
63 generics::{GenericParam, GenericParams, HasGenericParams}, 63 generics::{GenericParam, GenericParams, HasGenericParams},
@@ -78,7 +78,7 @@ pub use self::{
78pub use self::code_model::{ 78pub use self::code_model::{
79 docs::{DocDef, Docs, Documentation}, 79 docs::{DocDef, Docs, Documentation},
80 src::{HasBodySource, HasSource, Source}, 80 src::{HasBodySource, HasSource, Source},
81 BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 81 AdtDef, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
82 EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, 82 EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource,
83 Static, Struct, StructField, Trait, TypeAlias, Union, 83 Static, Struct, StructField, Trait, TypeAlias, Union,
84}; 84};
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 3d8691f53..1efaad4bc 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -69,7 +69,8 @@ use crate::{
69 diagnostics::DiagnosticSink, 69 diagnostics::DiagnosticSink,
70 ids::MacroDefId, 70 ids::MacroDefId,
71 nameres::diagnostics::DefDiagnostic, 71 nameres::diagnostics::DefDiagnostic,
72 AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, 72 AdtDef, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path,
73 PathKind, Trait,
73}; 74};
74 75
75pub(crate) use self::raw::{ImportSourceMap, RawItems}; 76pub(crate) use self::raw::{ImportSourceMap, RawItems};
@@ -425,7 +426,7 @@ impl CrateDefMap {
425 } 426 }
426 } 427 }
427 } 428 }
428 ModuleDef::Enum(e) => { 429 ModuleDef::AdtDef(AdtDef::Enum(e)) => {
429 // enum variant 430 // enum variant
430 tested_by!(can_import_enum_variant); 431 tested_by!(can_import_enum_variant);
431 match e.variant(db, &segment.name) { 432 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 03fbbd33f..ced1ebf1e 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -13,8 +13,8 @@ use crate::{
13 raw, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, 13 raw, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint,
14 Resolution, ResolveMode, 14 Resolution, ResolveMode,
15 }, 15 },
16 AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, 16 AdtDef, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind,
17 Struct, Trait, TypeAlias, Union, 17 Static, Struct, Trait, TypeAlias, Union,
18}; 18};
19 19
20pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 20pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -314,7 +314,7 @@ where
314 .push((module_id, import_id)); 314 .push((module_id, import_id));
315 } 315 }
316 } 316 }
317 Some(ModuleDef::Enum(e)) => { 317 Some(ModuleDef::AdtDef(AdtDef::Enum(e))) => {
318 tested_by!(glob_enum); 318 tested_by!(glob_enum);
319 // glob import from enum => just import all the variants 319 // glob import from enum => just import all the variants
320 let variants = e.variants(self.db); 320 let variants = e.variants(self.db);
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 1ed150f5a..251945112 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -15,7 +15,7 @@ use crate::{
15 name::{Name, SELF_PARAM, SELF_TYPE}, 15 name::{Name, SELF_PARAM, SELF_TYPE},
16 nameres::{CrateDefMap, CrateModuleId, PerNs}, 16 nameres::{CrateDefMap, CrateModuleId, PerNs},
17 path::Path, 17 path::Path,
18 Enum, MacroDef, ModuleDef, Struct, Trait, 18 AdtDef, Enum, MacroDef, ModuleDef, Struct, Trait,
19}; 19};
20 20
21#[derive(Debug, Clone, Default)] 21#[derive(Debug, Clone, Default)]
@@ -143,7 +143,7 @@ impl Resolver {
143 ) -> Option<Struct> { 143 ) -> Option<Struct> {
144 let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; 144 let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?;
145 match res { 145 match res {
146 Resolution::Def(ModuleDef::Struct(it)) => Some(it), 146 Resolution::Def(ModuleDef::AdtDef(AdtDef::Struct(it))) => Some(it),
147 _ => None, 147 _ => None,
148 } 148 }
149 } 149 }
@@ -152,7 +152,7 @@ impl Resolver {
152 pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option<Enum> { 152 pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option<Enum> {
153 let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; 153 let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?;
154 match res { 154 match res {
155 Resolution::Def(ModuleDef::Enum(it)) => Some(it), 155 Resolution::Def(ModuleDef::AdtDef(AdtDef::Enum(it))) => Some(it),
156 _ => None, 156 _ => None,
157 } 157 }
158 } 158 }
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 3970c49e3..725eec834 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> {
668 // FIXME remove the duplication between here and `Ty::from_path`? 668 // FIXME remove the duplication between here and `Ty::from_path`?
669 let substs = Ty::substs_from_path(self.db, resolver, path, def); 669 let substs = Ty::substs_from_path(self.db, resolver, path, def);
670 match def { 670 match def {
671 TypableDef::Struct(s) => { 671 TypableDef::AdtDef(AdtDef::Struct(s)) => {
672 let ty = s.ty(self.db); 672 let ty = s.ty(self.db);
673 let ty = self.insert_type_vars(ty.apply_substs(substs)); 673 let ty = self.insert_type_vars(ty.apply_substs(substs));
674 (ty, Some(s.into())) 674 (ty, Some(s.into()))
@@ -678,10 +678,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
678 let ty = self.insert_type_vars(ty.apply_substs(substs)); 678 let ty = self.insert_type_vars(ty.apply_substs(substs));
679 (ty, Some(var.into())) 679 (ty, Some(var.into()))
680 } 680 }
681 TypableDef::Union(_) 681 TypableDef::AdtDef(AdtDef::Enum(_))
682 | TypableDef::AdtDef(AdtDef::Union(_))
682 | TypableDef::TypeAlias(_) 683 | TypableDef::TypeAlias(_)
683 | TypableDef::Function(_) 684 | TypableDef::Function(_)
684 | TypableDef::Enum(_)
685 | TypableDef::Const(_) 685 | TypableDef::Const(_)
686 | TypableDef::Static(_) 686 | TypableDef::Static(_)
687 | TypableDef::BuiltinType(_) => (Ty::Unknown, None), 687 | TypableDef::BuiltinType(_) => (Ty::Unknown, None),
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index e67525a74..587dc12ee 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -172,9 +172,7 @@ impl Ty {
172 ) -> Substs { 172 ) -> Substs {
173 let def_generic: Option<GenericDef> = match resolved { 173 let def_generic: Option<GenericDef> = match resolved {
174 TypableDef::Function(func) => Some(func.into()), 174 TypableDef::Function(func) => Some(func.into()),
175 TypableDef::Struct(s) => Some(s.into()), 175 TypableDef::AdtDef(adt) => Some(adt.into()),
176 TypableDef::Union(u) => Some(u.into()),
177 TypableDef::Enum(e) => Some(e.into()),
178 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), 176 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()),
179 TypableDef::TypeAlias(t) => Some(t.into()), 177 TypableDef::TypeAlias(t) => Some(t.into()),
180 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, 178 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None,
@@ -193,9 +191,7 @@ impl Ty {
193 let last = path.segments.last().expect("path should have at least one segment"); 191 let last = path.segments.last().expect("path should have at least one segment");
194 let segment = match resolved { 192 let segment = match resolved {
195 TypableDef::Function(_) 193 TypableDef::Function(_)
196 | TypableDef::Struct(_) 194 | TypableDef::AdtDef(_)
197 | TypableDef::Union(_)
198 | TypableDef::Enum(_)
199 | TypableDef::Const(_) 195 | TypableDef::Const(_)
200 | TypableDef::Static(_) 196 | TypableDef::Static(_)
201 | TypableDef::TypeAlias(_) 197 | TypableDef::TypeAlias(_)
@@ -410,11 +406,11 @@ fn assoc_type_bindings_from_type_bound<'a>(
410pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty { 406pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty {
411 match (def, ns) { 407 match (def, ns) {
412 (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f), 408 (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f),
413 (TypableDef::Struct(s), Namespace::Types) => type_for_adt(db, s), 409 (TypableDef::AdtDef(AdtDef::Struct(s)), Namespace::Values) => {
414 (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), 410 type_for_struct_constructor(db, s)
415 (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), 411 }
412 (TypableDef::AdtDef(adt), Namespace::Types) => type_for_adt(db, adt),
416 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), 413 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
417 (TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u),
418 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), 414 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
419 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), 415 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c),
420 (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), 416 (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
422 418
423 // 'error' cases: 419 // 'error' cases:
424 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, 420 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
425 (TypableDef::Union(_), Namespace::Values) => Ty::Unknown, 421 (TypableDef::AdtDef(AdtDef::Union(_)), Namespace::Values) => Ty::Unknown,
426 (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, 422 (TypableDef::AdtDef(AdtDef::Enum(_)), Namespace::Values) => Ty::Unknown,
427 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, 423 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
428 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, 424 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
429 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, 425 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown,
@@ -608,34 +604,38 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
608#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 604#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
609pub enum TypableDef { 605pub enum TypableDef {
610 Function(Function), 606 Function(Function),
611 Struct(Struct), 607 AdtDef(AdtDef),
612 Union(Union),
613 Enum(Enum),
614 EnumVariant(EnumVariant), 608 EnumVariant(EnumVariant),
615 TypeAlias(TypeAlias), 609 TypeAlias(TypeAlias),
616 Const(Const), 610 Const(Const),
617 Static(Static), 611 Static(Static),
618 BuiltinType(BuiltinType), 612 BuiltinType(BuiltinType),
619} 613}
620impl_froms!( 614impl_froms!(TypableDef: Function, AdtDef, EnumVariant, TypeAlias, Const, Static, BuiltinType);
621 TypableDef: Function, 615
622 Struct, 616impl From<Struct> for TypableDef {
623 Union, 617 fn from(it: Struct) -> TypableDef {
624 Enum, 618 TypableDef::AdtDef(AdtDef::Struct(it))
625 EnumVariant, 619 }
626 TypeAlias, 620}
627 Const, 621
628 Static, 622impl From<Enum> for TypableDef {
629 BuiltinType 623 fn from(it: Enum) -> TypableDef {
630); 624 TypableDef::AdtDef(AdtDef::Enum(it))
625 }
626}
627
628impl From<Union> for TypableDef {
629 fn from(it: Union) -> TypableDef {
630 TypableDef::AdtDef(AdtDef::Union(it))
631 }
632}
631 633
632impl From<ModuleDef> for Option<TypableDef> { 634impl From<ModuleDef> for Option<TypableDef> {
633 fn from(def: ModuleDef) -> Option<TypableDef> { 635 fn from(def: ModuleDef) -> Option<TypableDef> {
634 let res = match def { 636 let res = match def {
635 ModuleDef::Function(f) => f.into(), 637 ModuleDef::Function(f) => f.into(),
636 ModuleDef::Struct(s) => s.into(), 638 ModuleDef::AdtDef(adt) => adt.into(),
637 ModuleDef::Union(u) => u.into(),
638 ModuleDef::Enum(e) => e.into(),
639 ModuleDef::EnumVariant(v) => v.into(), 639 ModuleDef::EnumVariant(v) => v.into(),
640 ModuleDef::TypeAlias(t) => t.into(), 640 ModuleDef::TypeAlias(t) => t.into(),
641 ModuleDef::Const(v) => v.into(), 641 ModuleDef::Const(v) => v.into(),