aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-25 14:51:17 +0000
committerGitHub <[email protected]>2019-11-25 14:51:17 +0000
commitecd1204804a2a3c8b9b98e4b9d18feef06ab51c7 (patch)
treed051e9bb71631cca33a1b4c23bf3f2576d1c0f56 /crates/ra_hir
parentbe00d74c7b61fb82bdade482e95035a21f9dd736 (diff)
parent1455663ea15ecbfbe87b4b5be6919aa35dd0b260 (diff)
Merge #2403
2403: Fixme for union fields r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs6
-rw-r--r--crates/ra_hir/src/code_model/src.rs8
-rw-r--r--crates/ra_hir/src/from_source.rs13
-rw-r--r--crates/ra_hir/src/ty.rs2
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs2
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs2
-rw-r--r--crates/ra_hir/src/ty/lower.rs5
7 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 534f1f8e9..ae730beb5 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -320,7 +320,7 @@ pub struct Struct {
320 320
321impl Struct { 321impl Struct {
322 pub fn module(self, db: &impl DefDatabase) -> Module { 322 pub fn module(self, db: &impl DefDatabase) -> Module {
323 Module { id: self.id.0.module(db) } 323 Module { id: self.id.module(db) }
324 } 324 }
325 325
326 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 326 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -369,11 +369,11 @@ pub struct Union {
369 369
370impl Union { 370impl Union {
371 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 371 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
372 db.struct_data(self.id.into()).name.clone() 372 db.union_data(self.id).name.clone()
373 } 373 }
374 374
375 pub fn module(self, db: &impl DefDatabase) -> Module { 375 pub fn module(self, db: &impl DefDatabase) -> Module {
376 Module { id: self.id.0.module(db) } 376 Module { id: self.id.module(db) }
377 } 377 }
378 378
379 pub fn ty(self, db: &impl HirDatabase) -> Ty { 379 pub fn ty(self, db: &impl HirDatabase) -> Ty {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index a4e317c20..076d86f2b 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -51,13 +51,13 @@ impl HasSource for StructField {
51impl HasSource for Struct { 51impl HasSource for Struct {
52 type Ast = ast::StructDef; 52 type Ast = ast::StructDef;
53 fn source(self, db: &impl DefDatabase) -> Source<ast::StructDef> { 53 fn source(self, db: &impl DefDatabase) -> Source<ast::StructDef> {
54 self.id.0.source(db) 54 self.id.source(db)
55 } 55 }
56} 56}
57impl HasSource for Union { 57impl HasSource for Union {
58 type Ast = ast::StructDef; 58 type Ast = ast::UnionDef;
59 fn source(self, db: &impl DefDatabase) -> Source<ast::StructDef> { 59 fn source(self, db: &impl DefDatabase) -> Source<ast::UnionDef> {
60 self.id.0.source(db) 60 self.id.source(db)
61 } 61 }
62} 62}
63impl HasSource for Enum { 63impl HasSource for Enum {
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 1e7c22774..95db7161b 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{AstItemDef, LocationCtx, ModuleId, StructId, StructOrUnionId, UnionId}; 3use hir_def::{AstItemDef, LocationCtx, ModuleId};
4use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; 4use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, AstNode, NameOwner}, 6 ast::{self, AstNode, NameOwner},
@@ -19,19 +19,18 @@ pub trait FromSource: Sized {
19 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self>; 19 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self>;
20} 20}
21 21
22// FIXIME: these two impls are wrong, `ast::StructDef` might produce either a struct or a union
23impl FromSource for Struct { 22impl FromSource for Struct {
24 type Ast = ast::StructDef; 23 type Ast = ast::StructDef;
25 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 24 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
26 let id: StructOrUnionId = from_source(db, src)?; 25 let id = from_source(db, src)?;
27 Some(Struct { id: StructId(id) }) 26 Some(Struct { id })
28 } 27 }
29} 28}
30impl FromSource for Union { 29impl FromSource for Union {
31 type Ast = ast::StructDef; 30 type Ast = ast::UnionDef;
32 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 31 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
33 let id: StructOrUnionId = from_source(db, src)?; 32 let id = from_source(db, src)?;
34 Some(Union { id: UnionId(id) }) 33 Some(Union { id })
35 } 34 }
36} 35}
37impl FromSource for Enum { 36impl FromSource for Enum {
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 8c045aaef..3cbcbd1d0 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -858,7 +858,7 @@ impl HirDisplay for ApplicationTy {
858 let name = match def { 858 let name = match def {
859 CallableDef::FunctionId(ff) => f.db.function_data(ff).name.clone(), 859 CallableDef::FunctionId(ff) => f.db.function_data(ff).name.clone(),
860 CallableDef::StructId(s) => { 860 CallableDef::StructId(s) => {
861 f.db.struct_data(s.0).name.clone().unwrap_or_else(Name::missing) 861 f.db.struct_data(s).name.clone().unwrap_or_else(Name::missing)
862 } 862 }
863 CallableDef::EnumVariantId(e) => { 863 CallableDef::EnumVariantId(e) => {
864 let enum_data = f.db.enum_data(e.parent); 864 let enum_data = f.db.enum_data(e.parent);
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index 4b53bba73..bb9a2e427 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -246,7 +246,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
246 ty_app!(TypeCtor::Adt(Adt::Struct(struct2)), st2), 246 ty_app!(TypeCtor::Adt(Adt::Struct(struct2)), st2),
247 ) if struct1 == struct2 => { 247 ) if struct1 == struct2 => {
248 let field_tys = self.db.field_types(struct1.id.into()); 248 let field_tys = self.db.field_types(struct1.id.into());
249 let struct_data = self.db.struct_data(struct1.id.0); 249 let struct_data = self.db.struct_data(struct1.id);
250 250
251 let mut fields = struct_data.variant_data.fields().iter(); 251 let mut fields = struct_data.variant_data.fields().iter();
252 let (last_field_id, _data) = fields.next_back()?; 252 let (last_field_id, _data) = fields.next_back()?;
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index 1d6df2b7a..994a6d7e9 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -263,6 +263,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
263 .clone() 263 .clone()
264 .subst(&a_ty.parameters) 264 .subst(&a_ty.parameters)
265 }), 265 }),
266 // FIXME:
267 TypeCtor::Adt(Adt::Union(_)) => None,
266 _ => None, 268 _ => None,
267 }, 269 },
268 _ => None, 270 _ => None,
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 27cfe00c1..eb51d31bd 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -560,7 +560,8 @@ pub(crate) fn field_types_query(
560 variant_id: VariantId, 560 variant_id: VariantId,
561) -> Arc<ArenaMap<LocalStructFieldId, Ty>> { 561) -> Arc<ArenaMap<LocalStructFieldId, Ty>> {
562 let (resolver, var_data) = match variant_id { 562 let (resolver, var_data) = match variant_id {
563 VariantId::StructId(it) => (it.resolver(db), db.struct_data(it.0).variant_data.clone()), 563 VariantId::StructId(it) => (it.resolver(db), db.struct_data(it).variant_data.clone()),
564 VariantId::UnionId(it) => (it.resolver(db), db.union_data(it).variant_data.clone()),
564 VariantId::EnumVariantId(it) => ( 565 VariantId::EnumVariantId(it) => (
565 it.parent.resolver(db), 566 it.parent.resolver(db),
566 db.enum_data(it.parent).variants[it.local_id].variant_data.clone(), 567 db.enum_data(it.parent).variants[it.local_id].variant_data.clone(),
@@ -818,7 +819,7 @@ impl CallableDef {
818 pub fn krate(self, db: &impl HirDatabase) -> CrateId { 819 pub fn krate(self, db: &impl HirDatabase) -> CrateId {
819 match self { 820 match self {
820 CallableDef::FunctionId(f) => f.lookup(db).module(db).krate, 821 CallableDef::FunctionId(f) => f.lookup(db).module(db).krate,
821 CallableDef::StructId(s) => s.0.module(db).krate, 822 CallableDef::StructId(s) => s.module(db).krate,
822 CallableDef::EnumVariantId(e) => e.parent.module(db).krate, 823 CallableDef::EnumVariantId(e) => e.parent.module(db).krate,
823 } 824 }
824 } 825 }