aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-09-12 22:34:52 +0100
committerAleksey Kladov <[email protected]>2019-09-12 22:34:52 +0100
commit114a1b878e95c20490af574550ea0825b7a8f9d1 (patch)
tree3fe7cb05dc4d92d19ecbb87bfafc4a9ff202153e /crates/ra_hir/src
parentbcf30d389c3744ab517372431eb7e1e1dfcc50df (diff)
rename AdtDef -> Adt
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs29
-rw-r--r--crates/ra_hir/src/expr/validation.rs6
-rw-r--r--crates/ra_hir/src/generics.rs18
-rw-r--r--crates/ra_hir/src/lang_item.rs8
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/nameres.rs6
-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.rs12
-rw-r--r--crates/ra_hir/src/ty/infer.rs14
-rw-r--r--crates/ra_hir/src/ty/lower.rs24
11 files changed, 64 insertions, 67 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index a10e795ce..c1938bd86 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -127,7 +127,7 @@ impl BuiltinType {
127pub enum ModuleDef { 127pub enum ModuleDef {
128 Module(Module), 128 Module(Module),
129 Function(Function), 129 Function(Function),
130 AdtDef(AdtDef), 130 Adt(Adt),
131 // Can't be directly declared, but can be imported. 131 // Can't be directly declared, but can be imported.
132 EnumVariant(EnumVariant), 132 EnumVariant(EnumVariant),
133 Const(Const), 133 Const(Const),
@@ -139,7 +139,7 @@ pub enum ModuleDef {
139impl_froms!( 139impl_froms!(
140 ModuleDef: Module, 140 ModuleDef: Module,
141 Function, 141 Function,
142 AdtDef(Struct, Enum, Union), 142 Adt(Struct, Enum, Union),
143 EnumVariant, 143 EnumVariant,
144 Const, 144 Const,
145 Static, 145 Static,
@@ -496,37 +496,38 @@ impl EnumVariant {
496 } 496 }
497} 497}
498 498
499/// A Data Type
499#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 500#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
500pub enum AdtDef { 501pub enum Adt {
501 Struct(Struct), 502 Struct(Struct),
502 Union(Union), 503 Union(Union),
503 Enum(Enum), 504 Enum(Enum),
504} 505}
505impl_froms!(AdtDef: Struct, Union, Enum); 506impl_froms!(Adt: Struct, Union, Enum);
506 507
507impl AdtDef { 508impl Adt {
508 pub fn ty(self, db: &impl HirDatabase) -> Ty { 509 pub fn ty(self, db: &impl HirDatabase) -> Ty {
509 match self { 510 match self {
510 AdtDef::Struct(it) => it.ty(db), 511 Adt::Struct(it) => it.ty(db),
511 AdtDef::Union(it) => it.ty(db), 512 Adt::Union(it) => it.ty(db),
512 AdtDef::Enum(it) => it.ty(db), 513 Adt::Enum(it) => it.ty(db),
513 } 514 }
514 } 515 }
515 516
516 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { 517 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
517 match self { 518 match self {
518 AdtDef::Struct(s) => s.module(db), 519 Adt::Struct(s) => s.module(db),
519 AdtDef::Union(s) => s.module(db), 520 Adt::Union(s) => s.module(db),
520 AdtDef::Enum(e) => e.module(db), 521 Adt::Enum(e) => e.module(db),
521 } 522 }
522 .krate(db) 523 .krate(db)
523 } 524 }
524 525
525 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { 526 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
526 match self { 527 match self {
527 AdtDef::Struct(it) => it.resolver(db), 528 Adt::Struct(it) => it.resolver(db),
528 AdtDef::Union(it) => it.resolver(db), 529 Adt::Union(it) => it.resolver(db),
529 AdtDef::Enum(it) => it.resolver(db), 530 Adt::Enum(it) => it.resolver(db),
530 } 531 }
531 } 532 }
532} 533}
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index 447b9264a..030ec53a2 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -10,7 +10,7 @@ use crate::{
10 name, 10 name,
11 path::{PathKind, PathSegment}, 11 path::{PathKind, PathSegment},
12 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 12 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
13 AdtDef, Function, Name, Path, 13 Adt, Function, Name, Path,
14}; 14};
15 15
16use super::{Expr, ExprId, RecordLitField}; 16use super::{Expr, ExprId, RecordLitField};
@@ -58,7 +58,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
58 } 58 }
59 59
60 let struct_def = match self.infer[id].as_adt() { 60 let struct_def = match self.infer[id].as_adt() {
61 Some((AdtDef::Struct(s), _)) => s, 61 Some((Adt::Struct(s), _)) => s,
62 _ => return, 62 _ => return,
63 }; 63 };
64 64
@@ -123,7 +123,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
123 _ => return, 123 _ => return,
124 }; 124 };
125 125
126 let std_result_ctor = TypeCtor::Adt(AdtDef::Enum(std_result_enum)); 126 let std_result_ctor = TypeCtor::Adt(Adt::Enum(std_result_enum));
127 let params = match &mismatch.expected { 127 let params = match &mismatch.expected {
128 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, 128 Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters,
129 _ => return, 129 _ => return,
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 74435c20a..77fb76bfc 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -12,8 +12,8 @@ use crate::{
12 name::SELF_TYPE, 12 name::SELF_TYPE,
13 path::Path, 13 path::Path,
14 type_ref::{TypeBound, TypeRef}, 14 type_ref::{TypeBound, TypeRef},
15 AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, 15 Adt, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait,
16 Trait, TypeAlias, Union, 16 TypeAlias, Union,
17}; 17};
18 18
19/// Data about a generic parameter (to a function, struct, impl, ...). 19/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -47,7 +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 AdtDef(AdtDef), 50 Adt(Adt),
51 Trait(Trait), 51 Trait(Trait),
52 TypeAlias(TypeAlias), 52 TypeAlias(TypeAlias),
53 ImplBlock(ImplBlock), 53 ImplBlock(ImplBlock),
@@ -57,7 +57,7 @@ pub enum GenericDef {
57} 57}
58impl_froms!( 58impl_froms!(
59 GenericDef: Function, 59 GenericDef: Function,
60 AdtDef(Struct, Enum, Union), 60 Adt(Struct, Enum, Union),
61 Trait, 61 Trait,
62 TypeAlias, 62 TypeAlias,
63 ImplBlock, 63 ImplBlock,
@@ -74,7 +74,7 @@ impl GenericParams {
74 GenericDef::Function(it) => it.container(db).map(GenericDef::from), 74 GenericDef::Function(it) => it.container(db).map(GenericDef::from),
75 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), 75 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
76 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), 76 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
77 GenericDef::AdtDef(_) | GenericDef::Trait(_) => None, 77 GenericDef::Adt(_) | GenericDef::Trait(_) => None,
78 GenericDef::ImplBlock(_) => None, 78 GenericDef::ImplBlock(_) => None,
79 }; 79 };
80 generics.parent_params = parent.map(|p| db.generic_params(p)); 80 generics.parent_params = parent.map(|p| db.generic_params(p));
@@ -82,9 +82,9 @@ impl GenericParams {
82 // FIXME: add `: Sized` bound for everything except for `Self` in traits 82 // FIXME: add `: Sized` bound for everything except for `Self` in traits
83 match def { 83 match def {
84 GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), 84 GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
85 GenericDef::AdtDef(AdtDef::Struct(it)) => generics.fill(&it.source(db).ast, start), 85 GenericDef::Adt(Adt::Struct(it)) => generics.fill(&it.source(db).ast, start),
86 GenericDef::AdtDef(AdtDef::Union(it)) => generics.fill(&it.source(db).ast, start), 86 GenericDef::Adt(Adt::Union(it)) => generics.fill(&it.source(db).ast, start),
87 GenericDef::AdtDef(AdtDef::Enum(it)) => generics.fill(&it.source(db).ast, start), 87 GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start),
88 GenericDef::Trait(it) => { 88 GenericDef::Trait(it) => {
89 // traits get the Self type as an implicit first type parameter 89 // traits get the Self type as an implicit first type parameter
90 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); 90 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
@@ -188,7 +188,7 @@ impl GenericDef {
188 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { 188 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
189 match self { 189 match self {
190 GenericDef::Function(inner) => inner.resolver(db), 190 GenericDef::Function(inner) => inner.resolver(db),
191 GenericDef::AdtDef(adt) => adt.resolver(db), 191 GenericDef::Adt(adt) => adt.resolver(db),
192 GenericDef::Trait(inner) => inner.resolver(db), 192 GenericDef::Trait(inner) => inner.resolver(db),
193 GenericDef::TypeAlias(inner) => inner.resolver(db), 193 GenericDef::TypeAlias(inner) => inner.resolver(db),
194 GenericDef::ImplBlock(inner) => inner.resolver(db), 194 GenericDef::ImplBlock(inner) => inner.resolver(db),
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs
index 87484d892..e3b71cec3 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 AdtDef, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait, 8 Adt, 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,10 +107,8 @@ 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::AdtDef(AdtDef::Enum(e)) => { 110 ModuleDef::Adt(Adt::Enum(e)) => self.collect_lang_item(db, e, LangItemTarget::Enum),
111 self.collect_lang_item(db, e, LangItemTarget::Enum) 111 ModuleDef::Adt(Adt::Struct(s)) => {
112 }
113 ModuleDef::AdtDef(AdtDef::Struct(s)) => {
114 self.collect_lang_item(db, s, LangItemTarget::Struct) 112 self.collect_lang_item(db, s, LangItemTarget::Struct)
115 } 113 }
116 ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), 114 ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function),
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 639e97c3d..508da3623 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -85,7 +85,7 @@ pub use self::{
85pub use self::code_model::{ 85pub use self::code_model::{
86 docs::{DocDef, Docs, Documentation}, 86 docs::{DocDef, Docs, Documentation},
87 src::{HasBodySource, HasSource, Source}, 87 src::{HasBodySource, HasSource, Source},
88 AdtDef, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 88 Adt, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
89 EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, 89 EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource,
90 Static, Struct, StructField, Trait, TypeAlias, Union, 90 Static, Struct, StructField, Trait, TypeAlias, Union,
91}; 91};
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index 1efaad4bc..3a3bf6b5f 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -69,8 +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 AdtDef, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, 72 Adt, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind,
73 PathKind, Trait, 73 Trait,
74}; 74};
75 75
76pub(crate) use self::raw::{ImportSourceMap, RawItems}; 76pub(crate) use self::raw::{ImportSourceMap, RawItems};
@@ -426,7 +426,7 @@ impl CrateDefMap {
426 } 426 }
427 } 427 }
428 } 428 }
429 ModuleDef::AdtDef(AdtDef::Enum(e)) => { 429 ModuleDef::Adt(Adt::Enum(e)) => {
430 // enum variant 430 // enum variant
431 tested_by!(can_import_enum_variant); 431 tested_by!(can_import_enum_variant);
432 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 ced1ebf1e..7d2f313c1 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 AdtDef, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, 16 Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static,
17 Static, Struct, Trait, TypeAlias, Union, 17 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::AdtDef(AdtDef::Enum(e))) => { 317 Some(ModuleDef::Adt(Adt::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 251945112..a77a9aeb1 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 AdtDef, Enum, MacroDef, ModuleDef, Struct, Trait, 18 Adt, 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::AdtDef(AdtDef::Struct(it))) => Some(it), 146 Resolution::Def(ModuleDef::Adt(Adt::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::AdtDef(AdtDef::Enum(it))) => Some(it), 155 Resolution::Def(ModuleDef::Adt(Adt::Enum(it))) => Some(it),
156 _ => None, 156 _ => None,
157 } 157 }
158 } 158 }
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index a3df08827..375850b92 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -16,7 +16,7 @@ use std::ops::Deref;
16use std::sync::Arc; 16use std::sync::Arc;
17use std::{fmt, mem}; 17use std::{fmt, mem};
18 18
19use crate::{db::HirDatabase, type_ref::Mutability, AdtDef, GenericParams, Name, Trait, TypeAlias}; 19use crate::{db::HirDatabase, type_ref::Mutability, Adt, GenericParams, Name, Trait, TypeAlias};
20use display::{HirDisplay, HirFormatter}; 20use display::{HirDisplay, HirFormatter};
21 21
22pub(crate) use autoderef::autoderef; 22pub(crate) use autoderef::autoderef;
@@ -47,7 +47,7 @@ pub enum TypeCtor {
47 Float(primitive::UncertainFloatTy), 47 Float(primitive::UncertainFloatTy),
48 48
49 /// Structures, enumerations and unions. 49 /// Structures, enumerations and unions.
50 Adt(AdtDef), 50 Adt(Adt),
51 51
52 /// The pointee of a string slice. Written as `str`. 52 /// The pointee of a string slice. Written as `str`.
53 Str, 53 Str,
@@ -458,7 +458,7 @@ impl Ty {
458 } 458 }
459 } 459 }
460 460
461 pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> { 461 pub fn as_adt(&self) -> Option<(Adt, &Substs)> {
462 match self { 462 match self {
463 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => { 463 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(adt_def), parameters }) => {
464 Some((*adt_def, parameters)) 464 Some((*adt_def, parameters))
@@ -726,9 +726,9 @@ impl HirDisplay for ApplicationTy {
726 } 726 }
727 TypeCtor::Adt(def_id) => { 727 TypeCtor::Adt(def_id) => {
728 let name = match def_id { 728 let name = match def_id {
729 AdtDef::Struct(s) => s.name(f.db), 729 Adt::Struct(s) => s.name(f.db),
730 AdtDef::Union(u) => u.name(f.db), 730 Adt::Union(u) => u.name(f.db),
731 AdtDef::Enum(e) => e.name(f.db), 731 Adt::Enum(e) => e.name(f.db),
732 } 732 }
733 .unwrap_or_else(Name::missing); 733 .unwrap_or_else(Name::missing);
734 write!(f, "{}", name)?; 734 write!(f, "{}", name)?;
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 725eec834..540a99b15 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -48,7 +48,7 @@ use crate::{
48 resolve::{Resolution, Resolver}, 48 resolve::{Resolution, Resolver},
49 ty::infer::diagnostics::InferenceDiagnostic, 49 ty::infer::diagnostics::InferenceDiagnostic,
50 type_ref::{Mutability, TypeRef}, 50 type_ref::{Mutability, TypeRef},
51 AdtDef, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path, 51 Adt, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path,
52 StructField, 52 StructField,
53}; 53};
54 54
@@ -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::AdtDef(AdtDef::Struct(s)) => { 671 TypableDef::Adt(Adt::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,8 +678,8 @@ 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::AdtDef(AdtDef::Enum(_)) 681 TypableDef::Adt(Adt::Enum(_))
682 | TypableDef::AdtDef(AdtDef::Union(_)) 682 | TypableDef::Adt(Adt::Union(_))
683 | TypableDef::TypeAlias(_) 683 | TypableDef::TypeAlias(_)
684 | TypableDef::Function(_) 684 | TypableDef::Function(_)
685 | TypableDef::Const(_) 685 | TypableDef::Const(_)
@@ -1185,7 +1185,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1185 let i = name.to_string().parse::<usize>().ok(); 1185 let i = name.to_string().parse::<usize>().ok();
1186 i.and_then(|i| a_ty.parameters.0.get(i).cloned()) 1186 i.and_then(|i| a_ty.parameters.0.get(i).cloned())
1187 } 1187 }
1188 TypeCtor::Adt(AdtDef::Struct(s)) => s.field(self.db, name).map(|field| { 1188 TypeCtor::Adt(Adt::Struct(s)) => s.field(self.db, name).map(|field| {
1189 self.write_field_resolution(tgt_expr, field); 1189 self.write_field_resolution(tgt_expr, field);
1190 field.ty(self.db).subst(&a_ty.parameters) 1190 field.ty(self.db).subst(&a_ty.parameters)
1191 }), 1191 }),
@@ -1489,7 +1489,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1489 trait_.associated_type_by_name(self.db, &name::OUTPUT) 1489 trait_.associated_type_by_name(self.db, &name::OUTPUT)
1490 } 1490 }
1491 1491
1492 fn resolve_boxed_box(&self) -> Option<AdtDef> { 1492 fn resolve_boxed_box(&self) -> Option<Adt> {
1493 let boxed_box_path = Path { 1493 let boxed_box_path = Path {
1494 kind: PathKind::Abs, 1494 kind: PathKind::Abs,
1495 segments: vec![ 1495 segments: vec![
@@ -1499,7 +1499,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1499 ], 1499 ],
1500 }; 1500 };
1501 let struct_ = self.resolver.resolve_known_struct(self.db, &boxed_box_path)?; 1501 let struct_ = self.resolver.resolve_known_struct(self.db, &boxed_box_path)?;
1502 Some(AdtDef::Struct(struct_)) 1502 Some(Adt::Struct(struct_))
1503 } 1503 }
1504} 1504}
1505 1505
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 105c893f0..946e9e9fb 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -20,7 +20,7 @@ use crate::{
20 nameres::Namespace, 20 nameres::Namespace,
21 path::{GenericArg, PathSegment}, 21 path::{GenericArg, PathSegment},
22 resolve::{Resolution, Resolver}, 22 resolve::{Resolution, Resolver},
23 ty::AdtDef, 23 ty::Adt,
24 type_ref::{TypeBound, TypeRef}, 24 type_ref::{TypeBound, TypeRef},
25 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, 25 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField,
26 Trait, TypeAlias, Union, 26 Trait, TypeAlias, Union,
@@ -172,7 +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::AdtDef(adt) => Some(adt.into()), 175 TypableDef::Adt(adt) => Some(adt.into()),
176 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), 176 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()),
177 TypableDef::TypeAlias(t) => Some(t.into()), 177 TypableDef::TypeAlias(t) => Some(t.into()),
178 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, 178 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None,
@@ -191,7 +191,7 @@ impl Ty {
191 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");
192 let segment = match resolved { 192 let segment = match resolved {
193 TypableDef::Function(_) 193 TypableDef::Function(_)
194 | TypableDef::AdtDef(_) 194 | TypableDef::Adt(_)
195 | TypableDef::Const(_) 195 | TypableDef::Const(_)
196 | TypableDef::Static(_) 196 | TypableDef::Static(_)
197 | TypableDef::TypeAlias(_) 197 | TypableDef::TypeAlias(_)
@@ -406,10 +406,8 @@ fn assoc_type_bindings_from_type_bound<'a>(
406pub(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 {
407 match (def, ns) { 407 match (def, ns) {
408 (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f), 408 (TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f),
409 (TypableDef::AdtDef(AdtDef::Struct(s)), Namespace::Values) => { 409 (TypableDef::Adt(Adt::Struct(s)), Namespace::Values) => type_for_struct_constructor(db, s),
410 type_for_struct_constructor(db, s) 410 (TypableDef::Adt(adt), Namespace::Types) => type_for_adt(db, adt),
411 }
412 (TypableDef::AdtDef(adt), Namespace::Types) => type_for_adt(db, adt),
413 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), 411 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
414 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), 412 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
415 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), 413 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c),
@@ -418,8 +416,8 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
418 416
419 // 'error' cases: 417 // 'error' cases:
420 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, 418 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
421 (TypableDef::AdtDef(AdtDef::Union(_)), Namespace::Values) => Ty::Unknown, 419 (TypableDef::Adt(Adt::Union(_)), Namespace::Values) => Ty::Unknown,
422 (TypableDef::AdtDef(AdtDef::Enum(_)), Namespace::Values) => Ty::Unknown, 420 (TypableDef::Adt(Adt::Enum(_)), Namespace::Values) => Ty::Unknown,
423 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, 421 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
424 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, 422 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
425 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, 423 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown,
@@ -587,7 +585,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) ->
587 Ty::apply(TypeCtor::FnDef(def.into()), substs) 585 Ty::apply(TypeCtor::FnDef(def.into()), substs)
588} 586}
589 587
590fn type_for_adt(db: &impl HirDatabase, adt: impl Into<AdtDef> + HasGenericParams) -> Ty { 588fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt> + HasGenericParams) -> Ty {
591 let generics = adt.generic_params(db); 589 let generics = adt.generic_params(db);
592 Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) 590 Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics))
593} 591}
@@ -604,7 +602,7 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
604#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 602#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
605pub enum TypableDef { 603pub enum TypableDef {
606 Function(Function), 604 Function(Function),
607 AdtDef(AdtDef), 605 Adt(Adt),
608 EnumVariant(EnumVariant), 606 EnumVariant(EnumVariant),
609 TypeAlias(TypeAlias), 607 TypeAlias(TypeAlias),
610 Const(Const), 608 Const(Const),
@@ -613,7 +611,7 @@ pub enum TypableDef {
613} 611}
614impl_froms!( 612impl_froms!(
615 TypableDef: Function, 613 TypableDef: Function,
616 AdtDef(Struct, Enum, Union), 614 Adt(Struct, Enum, Union),
617 EnumVariant, 615 EnumVariant,
618 TypeAlias, 616 TypeAlias,
619 Const, 617 Const,
@@ -625,7 +623,7 @@ impl From<ModuleDef> for Option<TypableDef> {
625 fn from(def: ModuleDef) -> Option<TypableDef> { 623 fn from(def: ModuleDef) -> Option<TypableDef> {
626 let res = match def { 624 let res = match def {
627 ModuleDef::Function(f) => f.into(), 625 ModuleDef::Function(f) => f.into(),
628 ModuleDef::AdtDef(adt) => adt.into(), 626 ModuleDef::Adt(adt) => adt.into(),
629 ModuleDef::EnumVariant(v) => v.into(), 627 ModuleDef::EnumVariant(v) => v.into(),
630 ModuleDef::TypeAlias(t) => t.into(), 628 ModuleDef::TypeAlias(t) => t.into(),
631 ModuleDef::Const(v) => v.into(), 629 ModuleDef::Const(v) => v.into(),