diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-12 22:35:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-12 22:35:28 +0100 |
commit | 1adf0519bcc8286c06e12aa7e5b16298addfea4a (patch) | |
tree | 3fe7cb05dc4d92d19ecbb87bfafc4a9ff202153e | |
parent | d8b621cf26b59ff5ae9379b50fc822590b6a3a4e (diff) | |
parent | 114a1b878e95c20490af574550ea0825b7a8f9d1 (diff) |
Merge #1835
1835: rename AdtDef -> Adt r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
21 files changed, 135 insertions, 141 deletions
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index cc3879562..543ed164c 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::iter; | 1 | use std::iter; |
2 | 2 | ||
3 | use hir::{db::HirDatabase, AdtDef, HasSource}; | 3 | use hir::{db::HirDatabase, Adt, HasSource}; |
4 | use ra_syntax::ast::{self, AstNode, NameOwner}; | 4 | use ra_syntax::ast::{self, AstNode, NameOwner}; |
5 | 5 | ||
6 | use crate::{ast_editor::AstBuilder, Assist, AssistCtx, AssistId}; | 6 | use crate::{ast_editor::AstBuilder, Assist, AssistCtx, AssistId}; |
@@ -60,7 +60,7 @@ fn resolve_enum_def( | |||
60 | let expr_ty = analyzer.type_of(db, &expr)?; | 60 | let expr_ty = analyzer.type_of(db, &expr)?; |
61 | 61 | ||
62 | analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() { | 62 | analyzer.autoderef(db, expr_ty).find_map(|ty| match ty.as_adt() { |
63 | Some((AdtDef::Enum(e), _)) => Some(e.source(db).ast), | 63 | Some((Adt::Enum(e), _)) => Some(e.source(db).ast), |
64 | _ => None, | 64 | _ => None, |
65 | }) | 65 | }) |
66 | } | 66 | } |
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}; | |||
9 | use crate::{ | 9 | use 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)] | ||
17 | pub enum AdtDef { | ||
18 | Struct(Struct), | ||
19 | Union(Union), | ||
20 | Enum(Enum), | ||
21 | } | ||
22 | impl_froms!(AdtDef: Struct, Union, Enum); | ||
23 | |||
24 | impl 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 | |||
35 | impl Struct { | 15 | impl 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..c1938bd86 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -127,9 +127,7 @@ impl BuiltinType { | |||
127 | pub enum ModuleDef { | 127 | pub enum ModuleDef { |
128 | Module(Module), | 128 | Module(Module), |
129 | Function(Function), | 129 | Function(Function), |
130 | Struct(Struct), | 130 | Adt(Adt), |
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 { | |||
141 | impl_froms!( | 139 | impl_froms!( |
142 | ModuleDef: Module, | 140 | ModuleDef: Module, |
143 | Function, | 141 | Function, |
144 | Struct, | 142 | Adt(Struct, Enum, Union), |
145 | Union, | ||
146 | Enum, | ||
147 | EnumVariant, | 143 | EnumVariant, |
148 | Const, | 144 | Const, |
149 | Static, | 145 | Static, |
@@ -500,6 +496,42 @@ impl EnumVariant { | |||
500 | } | 496 | } |
501 | } | 497 | } |
502 | 498 | ||
499 | /// A Data Type | ||
500 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
501 | pub enum Adt { | ||
502 | Struct(Struct), | ||
503 | Union(Union), | ||
504 | Enum(Enum), | ||
505 | } | ||
506 | impl_froms!(Adt: Struct, Union, Enum); | ||
507 | |||
508 | impl Adt { | ||
509 | pub fn ty(self, db: &impl HirDatabase) -> Ty { | ||
510 | match self { | ||
511 | Adt::Struct(it) => it.ty(db), | ||
512 | Adt::Union(it) => it.ty(db), | ||
513 | Adt::Enum(it) => it.ty(db), | ||
514 | } | ||
515 | } | ||
516 | |||
517 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | ||
518 | match self { | ||
519 | Adt::Struct(s) => s.module(db), | ||
520 | Adt::Union(s) => s.module(db), | ||
521 | Adt::Enum(e) => e.module(db), | ||
522 | } | ||
523 | .krate(db) | ||
524 | } | ||
525 | |||
526 | pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver { | ||
527 | match self { | ||
528 | Adt::Struct(it) => it.resolver(db), | ||
529 | Adt::Union(it) => it.resolver(db), | ||
530 | Adt::Enum(it) => it.resolver(db), | ||
531 | } | ||
532 | } | ||
533 | } | ||
534 | |||
503 | /// The defs which have a body. | 535 | /// The defs which have a body. |
504 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 536 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
505 | pub enum DefWithBody { | 537 | pub enum DefWithBody { |
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index c985dbdad..030ec53a2 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; | |||
4 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
5 | 5 | ||
6 | use crate::{ | 6 | use 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 | Adt, Function, Name, Path, |
15 | }; | 14 | }; |
16 | 15 | ||
17 | use super::{Expr, ExprId, RecordLitField}; | 16 | use super::{Expr, ExprId, RecordLitField}; |
@@ -59,7 +58,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
59 | } | 58 | } |
60 | 59 | ||
61 | let struct_def = match self.infer[id].as_adt() { | 60 | let struct_def = match self.infer[id].as_adt() { |
62 | Some((AdtDef::Struct(s), _)) => s, | 61 | Some((Adt::Struct(s), _)) => s, |
63 | _ => return, | 62 | _ => return, |
64 | }; | 63 | }; |
65 | 64 | ||
@@ -124,7 +123,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
124 | _ => return, | 123 | _ => return, |
125 | }; | 124 | }; |
126 | 125 | ||
127 | let std_result_ctor = TypeCtor::Adt(AdtDef::Enum(std_result_enum)); | 126 | let std_result_ctor = TypeCtor::Adt(Adt::Enum(std_result_enum)); |
128 | let params = match &mismatch.expected { | 127 | let params = match &mismatch.expected { |
129 | Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, | 128 | Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters, |
130 | _ => return, | 129 | _ => return, |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index c76df0698..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,9 +47,7 @@ pub struct WherePredicate { | |||
47 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | 47 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] |
48 | pub enum GenericDef { | 48 | pub enum GenericDef { |
49 | Function(Function), | 49 | Function(Function), |
50 | Struct(Struct), | 50 | Adt(Adt), |
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,14 @@ 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 | } |
60 | impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, EnumVariant); | 58 | impl_froms!( |
59 | GenericDef: Function, | ||
60 | Adt(Struct, Enum, Union), | ||
61 | Trait, | ||
62 | TypeAlias, | ||
63 | ImplBlock, | ||
64 | EnumVariant | ||
65 | ); | ||
61 | 66 | ||
62 | impl GenericParams { | 67 | impl GenericParams { |
63 | pub(crate) fn generic_params_query( | 68 | pub(crate) fn generic_params_query( |
@@ -69,10 +74,7 @@ impl GenericParams { | |||
69 | GenericDef::Function(it) => it.container(db).map(GenericDef::from), | 74 | GenericDef::Function(it) => it.container(db).map(GenericDef::from), |
70 | GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), | 75 | GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), |
71 | GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), | 76 | GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), |
72 | GenericDef::Struct(_) | 77 | GenericDef::Adt(_) | GenericDef::Trait(_) => None, |
73 | | GenericDef::Union(_) | ||
74 | | GenericDef::Enum(_) | ||
75 | | GenericDef::Trait(_) => None, | ||
76 | GenericDef::ImplBlock(_) => None, | 78 | GenericDef::ImplBlock(_) => None, |
77 | }; | 79 | }; |
78 | generics.parent_params = parent.map(|p| db.generic_params(p)); | 80 | generics.parent_params = parent.map(|p| db.generic_params(p)); |
@@ -80,9 +82,9 @@ impl GenericParams { | |||
80 | // FIXME: add `: Sized` bound for everything except for `Self` in traits | 82 | // FIXME: add `: Sized` bound for everything except for `Self` in traits |
81 | match def { | 83 | match def { |
82 | GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), | 84 | GenericDef::Function(it) => generics.fill(&it.source(db).ast, start), |
83 | GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start), | 85 | GenericDef::Adt(Adt::Struct(it)) => generics.fill(&it.source(db).ast, start), |
84 | GenericDef::Union(it) => generics.fill(&it.source(db).ast, start), | 86 | GenericDef::Adt(Adt::Union(it)) => generics.fill(&it.source(db).ast, start), |
85 | GenericDef::Enum(it) => generics.fill(&it.source(db).ast, start), | 87 | GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), |
86 | GenericDef::Trait(it) => { | 88 | GenericDef::Trait(it) => { |
87 | // traits get the Self type as an implicit first type parameter | 89 | // traits get the Self type as an implicit first type parameter |
88 | generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); | 90 | generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); |
@@ -186,9 +188,7 @@ impl GenericDef { | |||
186 | pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { | 188 | pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver { |
187 | match self { | 189 | match self { |
188 | GenericDef::Function(inner) => inner.resolver(db), | 190 | GenericDef::Function(inner) => inner.resolver(db), |
189 | GenericDef::Struct(inner) => inner.resolver(db), | 191 | GenericDef::Adt(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), | 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), |
@@ -206,16 +206,6 @@ impl From<Container> for GenericDef { | |||
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | impl 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 | |||
219 | pub trait HasGenericParams: Copy { | 209 | pub trait HasGenericParams: Copy { |
220 | fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>; | 210 | fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>; |
221 | } | 211 | } |
diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 832fdf1f5..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 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | db::{AstDatabase, DefDatabase, HirDatabase}, | 7 | db::{AstDatabase, DefDatabase, HirDatabase}, |
8 | 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,8 +107,10 @@ 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::Adt(Adt::Enum(e)) => self.collect_lang_item(db, e, LangItemTarget::Enum), |
111 | ModuleDef::Struct(s) => self.collect_lang_item(db, s, LangItemTarget::Struct), | 111 | ModuleDef::Adt(Adt::Struct(s)) => { |
112 | self.collect_lang_item(db, s, LangItemTarget::Struct) | ||
113 | } | ||
112 | ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), | 114 | ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function), |
113 | ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static), | 115 | ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static), |
114 | _ => {} | 116 | _ => {} |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 24ee84f86..508da3623 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -8,13 +8,20 @@ | |||
8 | //! applied. So, the relation between syntax and HIR is many-to-one. | 8 | //! applied. So, the relation between syntax and HIR is many-to-one. |
9 | 9 | ||
10 | macro_rules! impl_froms { | 10 | macro_rules! impl_froms { |
11 | ($e:ident: $($v:ident),*) => { | 11 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { |
12 | $( | 12 | $( |
13 | impl From<$v> for $e { | 13 | impl From<$v> for $e { |
14 | fn from(it: $v) -> $e { | 14 | fn from(it: $v) -> $e { |
15 | $e::$v(it) | 15 | $e::$v(it) |
16 | } | 16 | } |
17 | } | 17 | } |
18 | $($( | ||
19 | impl From<$sv> for $e { | ||
20 | fn from(it: $sv) -> $e { | ||
21 | $e::$v($v::$sv(it)) | ||
22 | } | ||
23 | } | ||
24 | )*)? | ||
18 | )* | 25 | )* |
19 | } | 26 | } |
20 | } | 27 | } |
@@ -57,7 +64,7 @@ use crate::{ | |||
57 | }; | 64 | }; |
58 | 65 | ||
59 | pub use self::{ | 66 | pub use self::{ |
60 | adt::{AdtDef, VariantDef}, | 67 | adt::VariantDef, |
61 | either::Either, | 68 | either::Either, |
62 | expr::ExprScopes, | 69 | expr::ExprScopes, |
63 | generics::{GenericParam, GenericParams, HasGenericParams}, | 70 | generics::{GenericParam, GenericParams, HasGenericParams}, |
@@ -78,7 +85,7 @@ pub use self::{ | |||
78 | pub use self::code_model::{ | 85 | pub use self::code_model::{ |
79 | docs::{DocDef, Docs, Documentation}, | 86 | docs::{DocDef, Docs, Documentation}, |
80 | src::{HasBodySource, HasSource, Source}, | 87 | src::{HasBodySource, HasSource, Source}, |
81 | BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, | 88 | Adt, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
82 | EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, | 89 | EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, |
83 | Static, Struct, StructField, Trait, TypeAlias, Union, | 90 | Static, Struct, StructField, Trait, TypeAlias, Union, |
84 | }; | 91 | }; |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 3d8691f53..3a3bf6b5f 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 | Adt, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, |
73 | Trait, | ||
73 | }; | 74 | }; |
74 | 75 | ||
75 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; | 76 | pub(crate) use self::raw::{ImportSourceMap, RawItems}; |
@@ -425,7 +426,7 @@ impl CrateDefMap { | |||
425 | } | 426 | } |
426 | } | 427 | } |
427 | } | 428 | } |
428 | ModuleDef::Enum(e) => { | 429 | ModuleDef::Adt(Adt::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..7d2f313c1 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -13,7 +13,7 @@ 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 | Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, |
17 | Struct, Trait, TypeAlias, Union, | 17 | Struct, Trait, TypeAlias, Union, |
18 | }; | 18 | }; |
19 | 19 | ||
@@ -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::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 1ed150f5a..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 | 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::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::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; | |||
16 | use std::sync::Arc; | 16 | use std::sync::Arc; |
17 | use std::{fmt, mem}; | 17 | use std::{fmt, mem}; |
18 | 18 | ||
19 | use crate::{db::HirDatabase, type_ref::Mutability, AdtDef, GenericParams, Name, Trait, TypeAlias}; | 19 | use crate::{db::HirDatabase, type_ref::Mutability, Adt, GenericParams, Name, Trait, TypeAlias}; |
20 | use display::{HirDisplay, HirFormatter}; | 20 | use display::{HirDisplay, HirFormatter}; |
21 | 21 | ||
22 | pub(crate) use autoderef::autoderef; | 22 | pub(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 3970c49e3..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::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,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::Adt(Adt::Enum(_)) |
682 | | TypableDef::Adt(Adt::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), |
@@ -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 e67525a74..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,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::Adt(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::Adt(_) |
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,9 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
410 | pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty { | 406 | pub(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::Adt(Adt::Struct(s)), Namespace::Values) => type_for_struct_constructor(db, s), |
414 | (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), | 410 | (TypableDef::Adt(adt), Namespace::Types) => type_for_adt(db, adt), |
415 | (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), | ||
416 | (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), |
417 | (TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u), | ||
418 | (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), | 412 | (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), |
419 | (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), | 413 | (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), |
420 | (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), | 414 | (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), |
@@ -422,8 +416,8 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace | |||
422 | 416 | ||
423 | // 'error' cases: | 417 | // 'error' cases: |
424 | (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, | 418 | (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, |
425 | (TypableDef::Union(_), Namespace::Values) => Ty::Unknown, | 419 | (TypableDef::Adt(Adt::Union(_)), Namespace::Values) => Ty::Unknown, |
426 | (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, | 420 | (TypableDef::Adt(Adt::Enum(_)), Namespace::Values) => Ty::Unknown, |
427 | (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, | 421 | (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, |
428 | (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, | 422 | (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, |
429 | (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, | 423 | (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, |
@@ -591,7 +585,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> | |||
591 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 585 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
592 | } | 586 | } |
593 | 587 | ||
594 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<AdtDef> + HasGenericParams) -> Ty { | 588 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt> + HasGenericParams) -> Ty { |
595 | let generics = adt.generic_params(db); | 589 | let generics = adt.generic_params(db); |
596 | Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) | 590 | Ty::apply(TypeCtor::Adt(adt.into()), Substs::identity(&generics)) |
597 | } | 591 | } |
@@ -608,9 +602,7 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { | |||
608 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 602 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
609 | pub enum TypableDef { | 603 | pub enum TypableDef { |
610 | Function(Function), | 604 | Function(Function), |
611 | Struct(Struct), | 605 | Adt(Adt), |
612 | Union(Union), | ||
613 | Enum(Enum), | ||
614 | EnumVariant(EnumVariant), | 606 | EnumVariant(EnumVariant), |
615 | TypeAlias(TypeAlias), | 607 | TypeAlias(TypeAlias), |
616 | Const(Const), | 608 | Const(Const), |
@@ -619,9 +611,7 @@ pub enum TypableDef { | |||
619 | } | 611 | } |
620 | impl_froms!( | 612 | impl_froms!( |
621 | TypableDef: Function, | 613 | TypableDef: Function, |
622 | Struct, | 614 | Adt(Struct, Enum, Union), |
623 | Union, | ||
624 | Enum, | ||
625 | EnumVariant, | 615 | EnumVariant, |
626 | TypeAlias, | 616 | TypeAlias, |
627 | Const, | 617 | Const, |
@@ -633,9 +623,7 @@ impl From<ModuleDef> for Option<TypableDef> { | |||
633 | fn from(def: ModuleDef) -> Option<TypableDef> { | 623 | fn from(def: ModuleDef) -> Option<TypableDef> { |
634 | let res = match def { | 624 | let res = match def { |
635 | ModuleDef::Function(f) => f.into(), | 625 | ModuleDef::Function(f) => f.into(), |
636 | ModuleDef::Struct(s) => s.into(), | 626 | ModuleDef::Adt(adt) => adt.into(), |
637 | ModuleDef::Union(u) => u.into(), | ||
638 | ModuleDef::Enum(e) => e.into(), | ||
639 | ModuleDef::EnumVariant(v) => v.into(), | 627 | ModuleDef::EnumVariant(v) => v.into(), |
640 | ModuleDef::TypeAlias(t) => t.into(), | 628 | ModuleDef::TypeAlias(t) => t.into(), |
641 | ModuleDef::Const(v) => v.into(), | 629 | ModuleDef::Const(v) => v.into(), |
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 2325cdf08..9e64c8659 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{AdtDef, Ty, TypeCtor}; | 1 | use hir::{Adt, Ty, TypeCtor}; |
2 | 2 | ||
3 | use crate::completion::completion_item::CompletionKind; | 3 | use crate::completion::completion_item::CompletionKind; |
4 | use crate::{ | 4 | use crate::{ |
@@ -37,7 +37,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
37 | for receiver in ctx.analyzer.autoderef(ctx.db, receiver) { | 37 | for receiver in ctx.analyzer.autoderef(ctx.db, receiver) { |
38 | if let Ty::Apply(a_ty) = receiver { | 38 | if let Ty::Apply(a_ty) = receiver { |
39 | match a_ty.ctor { | 39 | match a_ty.ctor { |
40 | TypeCtor::Adt(AdtDef::Struct(s)) => { | 40 | TypeCtor::Adt(Adt::Struct(s)) => { |
41 | for field in s.fields(ctx.db) { | 41 | for field in s.fields(ctx.db) { |
42 | acc.add_field(ctx, field, &a_ty.parameters); | 42 | acc.add_field(ctx, field, &a_ty.parameters); |
43 | } | 43 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 457a3d10c..4d3414f33 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 @@ | |||
1 | use hir::{Either, Resolution}; | 1 | use hir::{Adt, Either, Resolution}; |
2 | use ra_syntax::AstNode; | 2 | use ra_syntax::AstNode; |
3 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
4 | 4 | ||
@@ -37,19 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
37 | acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); | 37 | acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def)); |
38 | } | 38 | } |
39 | } | 39 | } |
40 | hir::ModuleDef::Enum(_) | 40 | hir::ModuleDef::Adt(_) | hir::ModuleDef::TypeAlias(_) => { |
41 | | hir::ModuleDef::Struct(_) | 41 | if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { |
42 | | hir::ModuleDef::Union(_) | ||
43 | | hir::ModuleDef::TypeAlias(_) => { | ||
44 | if let hir::ModuleDef::Enum(e) = def { | ||
45 | for variant in e.variants(ctx.db) { | 42 | for variant in e.variants(ctx.db) { |
46 | acc.add_enum_variant(ctx, variant); | 43 | acc.add_enum_variant(ctx, variant); |
47 | } | 44 | } |
48 | } | 45 | } |
49 | let ty = match def { | 46 | let ty = match def { |
50 | hir::ModuleDef::Enum(e) => e.ty(ctx.db), | 47 | hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), |
51 | hir::ModuleDef::Struct(s) => s.ty(ctx.db), | ||
52 | hir::ModuleDef::Union(u) => u.ty(ctx.db), | ||
53 | hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), | 48 | hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db), |
54 | _ => unreachable!(), | 49 | _ => unreachable!(), |
55 | }; | 50 | }; |
diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index fb02844fa..fb7f9feb8 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) { | |||
15 | _ => continue, | 15 | _ => continue, |
16 | }; | 16 | }; |
17 | match def { | 17 | match def { |
18 | hir::ModuleDef::Enum(..) | 18 | hir::ModuleDef::Adt(hir::Adt::Enum(..)) |
19 | | hir::ModuleDef::EnumVariant(..) | 19 | | hir::ModuleDef::EnumVariant(..) |
20 | | hir::ModuleDef::Const(..) | 20 | | hir::ModuleDef::Const(..) |
21 | | hir::ModuleDef::Module(..) => (), | 21 | | hir::ModuleDef::Module(..) => (), |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 5cabe9a32..95bbd34b7 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -67,9 +67,13 @@ impl Completions { | |||
67 | Resolution::Def(Function(func)) => { | 67 | Resolution::Def(Function(func)) => { |
68 | return self.add_function_with_name(ctx, Some(local_name), *func); | 68 | return self.add_function_with_name(ctx, Some(local_name), *func); |
69 | } | 69 | } |
70 | Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), | 70 | Resolution::Def(Adt(hir::Adt::Struct(it))) => { |
71 | Resolution::Def(Union(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), | 71 | (CompletionItemKind::Struct, it.docs(ctx.db)) |
72 | Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), | 72 | } |
73 | Resolution::Def(Adt(hir::Adt::Union(it))) => { | ||
74 | (CompletionItemKind::Struct, it.docs(ctx.db)) | ||
75 | } | ||
76 | Resolution::Def(Adt(hir::Adt::Enum(it))) => (CompletionItemKind::Enum, it.docs(ctx.db)), | ||
73 | Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), | 77 | Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), |
74 | Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), | 78 | Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), |
75 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), | 79 | 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 c85214bb3..03382ab3c 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -178,11 +178,11 @@ impl NavigationTarget { | |||
178 | ) | 178 | ) |
179 | } | 179 | } |
180 | 180 | ||
181 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { | 181 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::Adt) -> NavigationTarget { |
182 | match adt_def { | 182 | match adt_def { |
183 | hir::AdtDef::Struct(it) => NavigationTarget::from_def_source(db, it), | 183 | hir::Adt::Struct(it) => NavigationTarget::from_def_source(db, it), |
184 | hir::AdtDef::Union(it) => NavigationTarget::from_def_source(db, it), | 184 | hir::Adt::Union(it) => NavigationTarget::from_def_source(db, it), |
185 | hir::AdtDef::Enum(it) => NavigationTarget::from_def_source(db, it), | 185 | hir::Adt::Enum(it) => NavigationTarget::from_def_source(db, it), |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
@@ -193,9 +193,7 @@ impl NavigationTarget { | |||
193 | let nav = match module_def { | 193 | let nav = match module_def { |
194 | hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), | 194 | hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), |
195 | hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), | 195 | hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func), |
196 | hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), | 196 | hir::ModuleDef::Adt(it) => NavigationTarget::from_adt_def(db, it), |
197 | hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), | ||
198 | hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), | ||
199 | hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), | 197 | hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), |
200 | hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), | 198 | hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), |
201 | hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it), | 199 | 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 4b7847de8..28a6bef12 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{HasSource, HirDisplay}; | 1 | use hir::{Adt, HasSource, HirDisplay}; |
2 | use ra_db::SourceDatabase; | 2 | use ra_db::SourceDatabase; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{ | 4 | algo::{ |
@@ -129,9 +129,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
129 | } | 129 | } |
130 | } | 130 | } |
131 | hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), | 131 | hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), |
132 | hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)), | 132 | hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)), |
133 | hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)), | 133 | hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)), |
134 | hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)), | 134 | hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)), |
135 | hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), | 135 | hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), |
136 | hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), | 136 | hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), |
137 | hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), | 137 | hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), |
@@ -145,9 +145,9 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
145 | Some(SelfType(ty)) => { | 145 | Some(SelfType(ty)) => { |
146 | if let Some((adt_def, _)) = ty.as_adt() { | 146 | if let Some((adt_def, _)) = ty.as_adt() { |
147 | res.extend(match adt_def { | 147 | res.extend(match adt_def { |
148 | hir::AdtDef::Struct(it) => from_def_source(db, it), | 148 | hir::Adt::Struct(it) => from_def_source(db, it), |
149 | hir::AdtDef::Union(it) => from_def_source(db, it), | 149 | hir::Adt::Union(it) => from_def_source(db, it), |
150 | hir::AdtDef::Enum(it) => from_def_source(db, it), | 150 | hir::Adt::Enum(it) => from_def_source(db, it), |
151 | }) | 151 | }) |
152 | } | 152 | } |
153 | } | 153 | } |
diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 34a8bcc36..6c2a7b260 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs | |||
@@ -60,7 +60,7 @@ pub(crate) fn classify_name_ref( | |||
60 | let record_lit = field_expr.syntax().ancestors().find_map(ast::RecordLit::cast); | 60 | let record_lit = field_expr.syntax().ancestors().find_map(ast::RecordLit::cast); |
61 | 61 | ||
62 | if let Some(ty) = record_lit.and_then(|lit| analyzer.type_of(db, &lit.into())) { | 62 | if let Some(ty) = record_lit.and_then(|lit| analyzer.type_of(db, &lit.into())) { |
63 | if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() { | 63 | if let Some((hir::Adt::Struct(s), _)) = ty.as_adt() { |
64 | let hir_path = hir::Path::from_name_ref(name_ref); | 64 | let hir_path = hir::Path::from_name_ref(name_ref); |
65 | let hir_name = hir_path.as_ident().unwrap(); | 65 | let hir_name = hir_path.as_ident().unwrap(); |
66 | 66 | ||
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 06ccf0728..86ab3a260 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<HighlightedRa | |||
107 | Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type", | 107 | Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type", |
108 | Some(Def(hir::ModuleDef::Module(_))) => "module", | 108 | Some(Def(hir::ModuleDef::Module(_))) => "module", |
109 | Some(Def(hir::ModuleDef::Function(_))) => "function", | 109 | Some(Def(hir::ModuleDef::Function(_))) => "function", |
110 | Some(Def(hir::ModuleDef::Struct(_))) => "type", | 110 | Some(Def(hir::ModuleDef::Adt(_))) => "type", |
111 | Some(Def(hir::ModuleDef::Union(_))) => "type", | ||
112 | Some(Def(hir::ModuleDef::Enum(_))) => "type", | ||
113 | Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", | 111 | Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant", |
114 | Some(Def(hir::ModuleDef::Const(_))) => "constant", | 112 | Some(Def(hir::ModuleDef::Const(_))) => "constant", |
115 | Some(Def(hir::ModuleDef::Static(_))) => "constant", | 113 | Some(Def(hir::ModuleDef::Static(_))) => "constant", |