diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 38 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 21 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 10 |
9 files changed, 91 insertions, 26 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index e027eedd9..5e5905f15 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | Name, AsName, Struct, Enum, EnumVariant, Crate, | 13 | Name, AsName, Struct, Union, Enum, EnumVariant, Crate, |
14 | HirDatabase, HirFileId, StructField, FieldSource, | 14 | HirDatabase, HirFileId, StructField, FieldSource, |
15 | type_ref::TypeRef, DefDatabase, | 15 | type_ref::TypeRef, DefDatabase, |
16 | }; | 16 | }; |
@@ -18,14 +18,16 @@ use crate::{ | |||
18 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 18 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
19 | pub enum AdtDef { | 19 | pub enum AdtDef { |
20 | Struct(Struct), | 20 | Struct(Struct), |
21 | Union(Union), | ||
21 | Enum(Enum), | 22 | Enum(Enum), |
22 | } | 23 | } |
23 | impl_froms!(AdtDef: Struct, Enum); | 24 | impl_froms!(AdtDef: Struct, Union, Enum); |
24 | 25 | ||
25 | impl AdtDef { | 26 | impl AdtDef { |
26 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | 27 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { |
27 | match self { | 28 | match self { |
28 | AdtDef::Struct(s) => s.module(db), | 29 | AdtDef::Struct(s) => s.module(db), |
30 | AdtDef::Union(s) => s.module(db), | ||
29 | AdtDef::Enum(e) => e.module(db), | 31 | AdtDef::Enum(e) => e.module(db), |
30 | } | 32 | } |
31 | .krate(db) | 33 | .krate(db) |
@@ -38,6 +40,7 @@ impl Struct { | |||
38 | } | 40 | } |
39 | } | 41 | } |
40 | 42 | ||
43 | /// Note that we use `StructData` for unions as well! | ||
41 | #[derive(Debug, Clone, PartialEq, Eq)] | 44 | #[derive(Debug, Clone, PartialEq, Eq)] |
42 | pub struct StructData { | 45 | pub struct StructData { |
43 | pub(crate) name: Option<Name>, | 46 | pub(crate) name: Option<Name>, |
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 0c4a80bfa..970b78412 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -71,6 +71,7 @@ pub enum ModuleDef { | |||
71 | Module(Module), | 71 | Module(Module), |
72 | Function(Function), | 72 | Function(Function), |
73 | Struct(Struct), | 73 | Struct(Struct), |
74 | Union(Union), | ||
74 | Enum(Enum), | 75 | Enum(Enum), |
75 | // Can't be directly declared, but can be imported. | 76 | // Can't be directly declared, but can be imported. |
76 | EnumVariant(EnumVariant), | 77 | EnumVariant(EnumVariant), |
@@ -83,6 +84,7 @@ impl_froms!( | |||
83 | ModuleDef: Module, | 84 | ModuleDef: Module, |
84 | Function, | 85 | Function, |
85 | Struct, | 86 | Struct, |
87 | Union, | ||
86 | Enum, | 88 | Enum, |
87 | EnumVariant, | 89 | EnumVariant, |
88 | Const, | 90 | Const, |
@@ -326,6 +328,42 @@ impl Docs for Struct { | |||
326 | } | 328 | } |
327 | 329 | ||
328 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
331 | pub struct Union { | ||
332 | pub(crate) id: StructId, | ||
333 | } | ||
334 | |||
335 | impl Union { | ||
336 | pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { | ||
337 | self.id.source(db) | ||
338 | } | ||
339 | |||
340 | pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { | ||
341 | db.struct_data(Struct { id: self.id }).name.clone() | ||
342 | } | ||
343 | |||
344 | pub fn module(&self, db: &impl HirDatabase) -> Module { | ||
345 | self.id.module(db) | ||
346 | } | ||
347 | |||
348 | // FIXME move to a more general type | ||
349 | /// Builds a resolver for type references inside this union. | ||
350 | pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { | ||
351 | // take the outer scope... | ||
352 | let r = self.module(db).resolver(db); | ||
353 | // ...and add generic params, if present | ||
354 | let p = self.generic_params(db); | ||
355 | let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r }; | ||
356 | r | ||
357 | } | ||
358 | } | ||
359 | |||
360 | impl Docs for Union { | ||
361 | fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { | ||
362 | docs_from_ast(&*self.source(db).1) | ||
363 | } | ||
364 | } | ||
365 | |||
366 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
329 | pub struct Enum { | 367 | pub struct Enum { |
330 | pub(crate) id: EnumId, | 368 | pub(crate) id: EnumId, |
331 | } | 369 | } |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 79a7fa23a..8effbbe35 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -9,7 +9,7 @@ use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultT | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::{ HirDatabase, DefDatabase}, | 11 | db::{ HirDatabase, DefDatabase}, |
12 | Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef | 12 | Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, path::Path, type_ref::TypeRef, AdtDef |
13 | }; | 13 | }; |
14 | 14 | ||
15 | /// Data about a generic parameter (to a function, struct, impl, ...). | 15 | /// Data about a generic parameter (to a function, struct, impl, ...). |
@@ -42,12 +42,13 @@ pub struct WherePredicate { | |||
42 | pub enum GenericDef { | 42 | pub enum GenericDef { |
43 | Function(Function), | 43 | Function(Function), |
44 | Struct(Struct), | 44 | Struct(Struct), |
45 | Union(Union), | ||
45 | Enum(Enum), | 46 | Enum(Enum), |
46 | Trait(Trait), | 47 | Trait(Trait), |
47 | TypeAlias(TypeAlias), | 48 | TypeAlias(TypeAlias), |
48 | ImplBlock(ImplBlock), | 49 | ImplBlock(ImplBlock), |
49 | } | 50 | } |
50 | impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock); | 51 | impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock); |
51 | 52 | ||
52 | impl GenericParams { | 53 | impl GenericParams { |
53 | pub(crate) fn generic_params_query( | 54 | pub(crate) fn generic_params_query( |
@@ -58,7 +59,10 @@ impl GenericParams { | |||
58 | let parent = match def { | 59 | let parent = match def { |
59 | GenericDef::Function(it) => it.container(db).map(GenericDef::from), | 60 | GenericDef::Function(it) => it.container(db).map(GenericDef::from), |
60 | GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), | 61 | GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), |
61 | GenericDef::Struct(_) | GenericDef::Enum(_) | GenericDef::Trait(_) => None, | 62 | GenericDef::Struct(_) |
63 | | GenericDef::Union(_) | ||
64 | | GenericDef::Enum(_) | ||
65 | | GenericDef::Trait(_) => None, | ||
62 | GenericDef::ImplBlock(_) => None, | 66 | GenericDef::ImplBlock(_) => None, |
63 | }; | 67 | }; |
64 | generics.parent_params = parent.map(|p| db.generic_params(p)); | 68 | generics.parent_params = parent.map(|p| db.generic_params(p)); |
@@ -66,6 +70,7 @@ impl GenericParams { | |||
66 | match def { | 70 | match def { |
67 | GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), | 71 | GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), |
68 | GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start), | 72 | GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start), |
73 | GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), | ||
69 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), | 74 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), |
70 | GenericDef::Trait(it) => { | 75 | GenericDef::Trait(it) => { |
71 | // traits get the Self type as an implicit first type parameter | 76 | // traits get the Self type as an implicit first type parameter |
@@ -171,6 +176,7 @@ impl GenericDef { | |||
171 | match self { | 176 | match self { |
172 | GenericDef::Function(inner) => inner.resolver(db), | 177 | GenericDef::Function(inner) => inner.resolver(db), |
173 | GenericDef::Struct(inner) => inner.resolver(db), | 178 | GenericDef::Struct(inner) => inner.resolver(db), |
179 | GenericDef::Union(inner) => inner.resolver(db), | ||
174 | GenericDef::Enum(inner) => inner.resolver(db), | 180 | GenericDef::Enum(inner) => inner.resolver(db), |
175 | GenericDef::Trait(inner) => inner.resolver(db), | 181 | GenericDef::Trait(inner) => inner.resolver(db), |
176 | GenericDef::TypeAlias(inner) => inner.resolver(db), | 182 | GenericDef::TypeAlias(inner) => inner.resolver(db), |
@@ -192,6 +198,7 @@ impl From<crate::adt::AdtDef> for GenericDef { | |||
192 | fn from(adt: crate::adt::AdtDef) -> Self { | 198 | fn from(adt: crate::adt::AdtDef) -> Self { |
193 | match adt { | 199 | match adt { |
194 | AdtDef::Struct(s) => s.into(), | 200 | AdtDef::Struct(s) => s.into(), |
201 | AdtDef::Union(u) => u.into(), | ||
195 | AdtDef::Enum(e) => e.into(), | 202 | AdtDef::Enum(e) => e.into(), |
196 | } | 203 | } |
197 | } | 204 | } |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0c6d7c2b7..0135644db 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -77,7 +77,7 @@ pub use self::code_model_api::{ | |||
77 | Crate, CrateDependency, | 77 | Crate, CrateDependency, |
78 | DefWithBody, | 78 | DefWithBody, |
79 | Module, ModuleDef, ModuleSource, | 79 | Module, ModuleDef, ModuleSource, |
80 | Struct, Enum, EnumVariant, | 80 | Struct, Union, Enum, EnumVariant, |
81 | Function, FnSignature, | 81 | Function, FnSignature, |
82 | StructField, FieldSource, | 82 | StructField, FieldSource, |
83 | Static, Const, ConstSignature, | 83 | Static, Const, ConstSignature, |
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index c615d80c3..621236551 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -6,7 +6,7 @@ use ra_db::FileId; | |||
6 | use ra_syntax::ast; | 6 | use ra_syntax::ast; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, | 9 | Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, |
10 | DefDatabase, HirFileId, Name, Path, | 10 | DefDatabase, HirFileId, Name, Path, |
11 | KnownName, | 11 | KnownName, |
12 | nameres::{ | 12 | nameres::{ |
@@ -495,6 +495,10 @@ where | |||
495 | let s = def!(Struct, ast_id); | 495 | let s = def!(Struct, ast_id); |
496 | PerNs::both(s, s) | 496 | PerNs::both(s, s) |
497 | } | 497 | } |
498 | raw::DefKind::Union(ast_id) => { | ||
499 | let s = def!(Union, ast_id); | ||
500 | PerNs::both(s, s) | ||
501 | } | ||
498 | raw::DefKind::Enum(ast_id) => PerNs::types(def!(Enum, ast_id)), | 502 | raw::DefKind::Enum(ast_id) => PerNs::types(def!(Enum, ast_id)), |
499 | raw::DefKind::Const(ast_id) => PerNs::values(def!(Const, ast_id)), | 503 | raw::DefKind::Const(ast_id) => PerNs::values(def!(Const, ast_id)), |
500 | raw::DefKind::Static(ast_id) => PerNs::values(def!(Static, ast_id)), | 504 | raw::DefKind::Static(ast_id) => PerNs::values(def!(Static, ast_id)), |
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index bd32b264b..1b4dcbb7a 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -1,7 +1,4 @@ | |||
1 | use std::{ | 1 | use std::{sync::Arc, ops::Index}; |
2 | sync::Arc, | ||
3 | ops::Index, | ||
4 | }; | ||
5 | 2 | ||
6 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
7 | use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap}; | 4 | use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap}; |
@@ -10,10 +7,7 @@ use ra_syntax::{ | |||
10 | ast::{self, NameOwner, AttrsOwner}, | 7 | ast::{self, NameOwner, AttrsOwner}, |
11 | }; | 8 | }; |
12 | 9 | ||
13 | use crate::{ | 10 | use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either}; |
14 | DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, | ||
15 | AstIdMap, FileAstId, Either, | ||
16 | }; | ||
17 | 11 | ||
18 | /// `RawItems` is a set of top-level items in a file (except for impls). | 12 | /// `RawItems` is a set of top-level items in a file (except for impls). |
19 | /// | 13 | /// |
@@ -161,6 +155,7 @@ pub(super) struct DefData { | |||
161 | pub(super) enum DefKind { | 155 | pub(super) enum DefKind { |
162 | Function(FileAstId<ast::FnDef>), | 156 | Function(FileAstId<ast::FnDef>), |
163 | Struct(FileAstId<ast::StructDef>), | 157 | Struct(FileAstId<ast::StructDef>), |
158 | Union(FileAstId<ast::StructDef>), | ||
164 | Enum(FileAstId<ast::EnumDef>), | 159 | Enum(FileAstId<ast::EnumDef>), |
165 | Const(FileAstId<ast::ConstDef>), | 160 | Const(FileAstId<ast::ConstDef>), |
166 | Static(FileAstId<ast::StaticDef>), | 161 | Static(FileAstId<ast::StaticDef>), |
@@ -215,7 +210,13 @@ impl RawItemsCollector { | |||
215 | return; | 210 | return; |
216 | } | 211 | } |
217 | ast::ModuleItemKind::StructDef(it) => { | 212 | ast::ModuleItemKind::StructDef(it) => { |
218 | (DefKind::Struct(self.source_ast_id_map.ast_id(it)), it.name()) | 213 | let id = self.source_ast_id_map.ast_id(it); |
214 | let name = it.name(); | ||
215 | if it.is_union() { | ||
216 | (DefKind::Union(id), name) | ||
217 | } else { | ||
218 | (DefKind::Struct(id), name) | ||
219 | } | ||
219 | } | 220 | } |
220 | ast::ModuleItemKind::EnumDef(it) => { | 221 | ast::ModuleItemKind::EnumDef(it) => { |
221 | (DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name()) | 222 | (DefKind::Enum(self.source_ast_id_map.ast_id(it)), it.name()) |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 3679a2242..76d34c12b 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -536,6 +536,7 @@ impl HirDisplay for ApplicationTy { | |||
536 | TypeCtor::Adt(def_id) => { | 536 | TypeCtor::Adt(def_id) => { |
537 | let name = match def_id { | 537 | let name = match def_id { |
538 | AdtDef::Struct(s) => s.name(f.db), | 538 | AdtDef::Struct(s) => s.name(f.db), |
539 | AdtDef::Union(u) => u.name(f.db), | ||
539 | AdtDef::Enum(e) => e.name(f.db), | 540 | AdtDef::Enum(e) => e.name(f.db), |
540 | } | 541 | } |
541 | .unwrap_or_else(Name::missing); | 542 | .unwrap_or_else(Name::missing); |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index a48272981..7d8250292 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -27,13 +27,13 @@ use ra_prof::profile; | |||
27 | use test_utils::tested_by; | 27 | use test_utils::tested_by; |
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
30 | Function, StructField, Path, Name, | 30 | Function, StructField, Path, Name, FnSignature, AdtDef, ConstSignature, HirDatabase, |
31 | FnSignature, AdtDef,ConstSignature, | 31 | DefWithBody, ImplItem, |
32 | HirDatabase, | ||
33 | DefWithBody, | ||
34 | ImplItem, | ||
35 | type_ref::{TypeRef, Mutability}, | 32 | type_ref::{TypeRef, Mutability}, |
36 | expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat,Array, self}, | 33 | expr::{ |
34 | Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, | ||
35 | FieldPat, Array, self, | ||
36 | }, | ||
37 | generics::{GenericParams, HasGenericParams}, | 37 | generics::{GenericParams, HasGenericParams}, |
38 | path::{GenericArgs, GenericArg}, | 38 | path::{GenericArgs, GenericArg}, |
39 | ModuleDef, | 39 | ModuleDef, |
@@ -644,7 +644,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
644 | let ty = self.insert_type_vars(ty.apply_substs(substs)); | 644 | let ty = self.insert_type_vars(ty.apply_substs(substs)); |
645 | (ty, Some(var.into())) | 645 | (ty, Some(var.into())) |
646 | } | 646 | } |
647 | TypableDef::TypeAlias(_) | 647 | TypableDef::Union(_) |
648 | | TypableDef::TypeAlias(_) | ||
648 | | TypableDef::Function(_) | 649 | | TypableDef::Function(_) |
649 | | TypableDef::Enum(_) | 650 | | TypableDef::Enum(_) |
650 | | TypableDef::Const(_) | 651 | | TypableDef::Const(_) |
@@ -1407,7 +1408,11 @@ impl Expectation { | |||
1407 | } | 1408 | } |
1408 | 1409 | ||
1409 | mod diagnostics { | 1410 | mod diagnostics { |
1410 | use crate::{expr::ExprId, diagnostics::{DiagnosticSink, NoSuchField}, HirDatabase, Function}; | 1411 | use crate::{ |
1412 | expr::ExprId, | ||
1413 | diagnostics::{DiagnosticSink, NoSuchField}, | ||
1414 | HirDatabase, Function, | ||
1415 | }; | ||
1411 | 1416 | ||
1412 | #[derive(Debug, PartialEq, Eq, Clone)] | 1417 | #[derive(Debug, PartialEq, Eq, Clone)] |
1413 | pub(super) enum InferenceDiagnostic { | 1418 | pub(super) enum InferenceDiagnostic { |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index a1a2d0f6b..7defa7a9b 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -9,7 +9,7 @@ use std::sync::Arc; | |||
9 | use std::iter; | 9 | use std::iter; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | Function, Struct, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, | 12 | Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, |
13 | HirDatabase, | 13 | HirDatabase, |
14 | type_ref::TypeRef, | 14 | type_ref::TypeRef, |
15 | name::KnownName, | 15 | name::KnownName, |
@@ -124,6 +124,7 @@ impl Ty { | |||
124 | let def_generic: Option<GenericDef> = match resolved { | 124 | let def_generic: Option<GenericDef> = match resolved { |
125 | TypableDef::Function(func) => Some(func.into()), | 125 | TypableDef::Function(func) => Some(func.into()), |
126 | TypableDef::Struct(s) => Some(s.into()), | 126 | TypableDef::Struct(s) => Some(s.into()), |
127 | TypableDef::Union(u) => Some(u.into()), | ||
127 | TypableDef::Enum(e) => Some(e.into()), | 128 | TypableDef::Enum(e) => Some(e.into()), |
128 | TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), | 129 | TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), |
129 | TypableDef::TypeAlias(t) => Some(t.into()), | 130 | TypableDef::TypeAlias(t) => Some(t.into()), |
@@ -144,6 +145,7 @@ impl Ty { | |||
144 | let segment = match resolved { | 145 | let segment = match resolved { |
145 | TypableDef::Function(_) | 146 | TypableDef::Function(_) |
146 | | TypableDef::Struct(_) | 147 | | TypableDef::Struct(_) |
148 | | TypableDef::Union(_) | ||
147 | | TypableDef::Enum(_) | 149 | | TypableDef::Enum(_) |
148 | | TypableDef::Const(_) | 150 | | TypableDef::Const(_) |
149 | | TypableDef::Static(_) | 151 | | TypableDef::Static(_) |
@@ -293,12 +295,14 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace | |||
293 | (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), | 295 | (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), |
294 | (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), | 296 | (TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e), |
295 | (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), | 297 | (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), |
298 | (TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u), | ||
296 | (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), | 299 | (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), |
297 | (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), | 300 | (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), |
298 | (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), | 301 | (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c), |
299 | 302 | ||
300 | // 'error' cases: | 303 | // 'error' cases: |
301 | (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, | 304 | (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, |
305 | (TypableDef::Union(_), Namespace::Values) => Ty::Unknown, | ||
302 | (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, | 306 | (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, |
303 | (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, | 307 | (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, |
304 | (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, | 308 | (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, |
@@ -467,19 +471,21 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { | |||
467 | pub enum TypableDef { | 471 | pub enum TypableDef { |
468 | Function(Function), | 472 | Function(Function), |
469 | Struct(Struct), | 473 | Struct(Struct), |
474 | Union(Union), | ||
470 | Enum(Enum), | 475 | Enum(Enum), |
471 | EnumVariant(EnumVariant), | 476 | EnumVariant(EnumVariant), |
472 | TypeAlias(TypeAlias), | 477 | TypeAlias(TypeAlias), |
473 | Const(Const), | 478 | Const(Const), |
474 | Static(Static), | 479 | Static(Static), |
475 | } | 480 | } |
476 | impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias, Const, Static); | 481 | impl_froms!(TypableDef: Function, Struct, Union, Enum, EnumVariant, TypeAlias, Const, Static); |
477 | 482 | ||
478 | impl From<ModuleDef> for Option<TypableDef> { | 483 | impl From<ModuleDef> for Option<TypableDef> { |
479 | fn from(def: ModuleDef) -> Option<TypableDef> { | 484 | fn from(def: ModuleDef) -> Option<TypableDef> { |
480 | let res = match def { | 485 | let res = match def { |
481 | ModuleDef::Function(f) => f.into(), | 486 | ModuleDef::Function(f) => f.into(), |
482 | ModuleDef::Struct(s) => s.into(), | 487 | ModuleDef::Struct(s) => s.into(), |
488 | ModuleDef::Union(u) => u.into(), | ||
483 | ModuleDef::Enum(e) => e.into(), | 489 | ModuleDef::Enum(e) => e.into(), |
484 | ModuleDef::EnumVariant(v) => v.into(), | 490 | ModuleDef::EnumVariant(v) => v.into(), |
485 | ModuleDef::TypeAlias(t) => t.into(), | 491 | ModuleDef::TypeAlias(t) => t.into(), |