From 6294fd5ec9c6946bdd91f1274956c573f9f2a136 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Nov 2019 15:34:00 +0300 Subject: Unfork struct and union ids --- crates/ra_hir/src/adt.rs | 2 +- crates/ra_hir/src/code_model.rs | 12 ++++++------ crates/ra_hir/src/code_model/src.rs | 4 ++-- crates/ra_hir/src/expr/scope.rs | 5 +---- crates/ra_hir/src/from_source.rs | 10 ++++++---- crates/ra_hir/src/ty/lower.rs | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 0436d20b7..945f236c2 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -12,7 +12,7 @@ use crate::{ impl Struct { pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc { - db.struct_data(self.id).variant_data.clone() + db.struct_data(self.id.into()).variant_data.clone() } } diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9d0db8024..e5bfad3ca 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -288,7 +288,7 @@ pub struct Struct { impl Struct { pub fn module(self, db: &impl DefDatabase) -> Module { - Module { id: self.id.module(db) } + Module { id: self.id.0.module(db) } } pub fn krate(self, db: &impl DefDatabase) -> Option { @@ -296,11 +296,11 @@ impl Struct { } pub fn name(self, db: &impl DefDatabase) -> Option { - db.struct_data(self.id).name.clone() + db.struct_data(self.id.into()).name.clone() } pub fn fields(self, db: &impl HirDatabase) -> Vec { - db.struct_data(self.id) + db.struct_data(self.id.into()) .variant_data .fields() .into_iter() @@ -310,7 +310,7 @@ impl Struct { } pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option { - db.struct_data(self.id) + db.struct_data(self.id.into()) .variant_data .fields() .into_iter() @@ -346,11 +346,11 @@ pub struct Union { impl Union { pub fn name(self, db: &impl DefDatabase) -> Option { - db.union_data(self.id).name.clone() + db.struct_data(self.id.into()).name.clone() } pub fn module(self, db: &impl HirDatabase) -> Module { - Module { id: self.id.module(db) } + Module { id: self.id.0.module(db) } } 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 6d116ee75..247ae3e55 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -78,13 +78,13 @@ impl HasSource for StructField { impl HasSource for Struct { type Ast = ast::StructDef; fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source { - self.id.source(db) + self.id.0.source(db) } } impl HasSource for Union { type Ast = ast::StructDef; fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source { - self.id.source(db) + self.id.0.source(db) } } impl HasSource for Enum { diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index c14c2ab66..5a1eade2c 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -67,10 +67,7 @@ impl ExprScopes { &self.scopes[scope].entries } - pub(crate) fn scope_chain<'a>( - &'a self, - scope: Option, - ) -> impl Iterator + 'a { + pub(crate) fn scope_chain(&self, scope: Option) -> impl Iterator + '_ { std::iter::successors(scope, move |&scope| self.scopes[scope].parent) } diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 9899bdbbc..c95d2cdd0 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use hir_def::{StructId, StructOrUnionId, UnionId}; use hir_expand::name::AsName; use ra_syntax::ast::{self, AstNode, NameOwner}; @@ -15,18 +16,19 @@ pub trait FromSource: Sized { fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option; } +// FIXIME: these two impls are wrong, `ast::StructDef` might produce either a struct or a union impl FromSource for Struct { type Ast = ast::StructDef; fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { - let id = from_source(db, src)?; - Some(Struct { id }) + let id: StructOrUnionId = from_source(db, src)?; + Some(Struct { id: StructId(id) }) } } impl FromSource for Union { type Ast = ast::StructDef; fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { - let id = from_source(db, src)?; - Some(Union { id }) + let id: StructOrUnionId = from_source(db, src)?; + Some(Union { id: UnionId(id) }) } } impl FromSource for Enum { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index d26b16cb2..1fed5025e 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -665,7 +665,7 @@ fn type_for_builtin(def: BuiltinType) -> Ty { } fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { - let struct_data = db.struct_data(def.id); + let struct_data = db.struct_data(def.id.into()); let fields = match struct_data.variant_data.fields() { Some(fields) => fields, None => panic!("fn_sig_for_struct_constructor called on unit struct"), @@ -681,7 +681,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { /// Build the type of a tuple struct constructor. fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { - let struct_data = db.struct_data(def.id); + let struct_data = db.struct_data(def.id.into()); if struct_data.variant_data.fields().is_none() { return type_for_adt(db, def); // Unit struct } -- cgit v1.2.3