aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/adt.rs23
-rw-r--r--crates/ra_hir/src/lib.rs5
-rw-r--r--crates/ra_hir/src/ty.rs19
3 files changed, 23 insertions, 24 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index ad3f9c405..6b13b464d 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -3,17 +3,32 @@
3 3
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use ra_syntax::{ 6use ra_syntax::ast::{self, NameOwner, StructFlavor};
7 ast::{self, NameOwner, StructFlavor}
8};
9 7
10use crate::{ 8use crate::{
11 Name, AsName, Struct, Enum, EnumVariant, 9 Name, AsName, Struct, Enum, EnumVariant, Crate,
12 HirDatabase, 10 HirDatabase,
13 type_ref::TypeRef, 11 type_ref::TypeRef,
14 ids::LocationCtx, 12 ids::LocationCtx,
15}; 13};
16 14
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
16pub enum AdtDef {
17 Struct(Struct),
18 Enum(Enum),
19}
20impl_froms!(AdtDef: Struct, Enum);
21
22impl AdtDef {
23 pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
24 match self {
25 AdtDef::Struct(s) => s.module(db),
26 AdtDef::Enum(e) => e.module(db),
27 }
28 .krate(db)
29 }
30}
31
17impl Struct { 32impl Struct {
18 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> { 33 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
19 db.struct_data((*self).into()).variant_data.clone() 34 db.struct_data((*self).into()).variant_data.clone()
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 644affd44..596f9c38c 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -55,10 +55,11 @@ pub use self::{
55 ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner}, 55 ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
56 macros::{MacroDef, MacroInput, MacroExpansion}, 56 macros::{MacroDef, MacroInput, MacroExpansion},
57 nameres::{ItemMap, PerNs, Namespace, Resolution}, 57 nameres::{ItemMap, PerNs, Namespace, Resolution},
58 ty::{Ty, AdtDef}, 58 ty::Ty,
59 impl_block::{ImplBlock, ImplItem}, 59 impl_block::{ImplBlock, ImplItem},
60 code_model_impl::function::{FnScopes, ScopesWithSyntaxMapping}, 60 code_model_impl::function::{FnScopes, ScopesWithSyntaxMapping},
61 docs::{Docs, Documentation} 61 docs::{Docs, Documentation},
62 adt::AdtDef,
62}; 63};
63 64
64pub use self::code_model_api::{ 65pub use self::code_model_api::{
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 1d5624f8f..c7f77e7a3 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -31,7 +31,7 @@ use rustc_hash::FxHashMap;
31 31
32use crate::{ 32use crate::{
33 Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock, 33 Module, Function, Struct, StructField, Enum, EnumVariant, Path, Name, ImplBlock,
34 FnSignature, FnScopes, ModuleDef, Crate, 34 FnSignature, FnScopes, ModuleDef, AdtDef,
35 db::HirDatabase, 35 db::HirDatabase,
36 type_ref::{TypeRef, Mutability}, 36 type_ref::{TypeRef, Mutability},
37 name::KnownName, 37 name::KnownName,
@@ -162,23 +162,6 @@ impl Substs {
162 } 162 }
163} 163}
164 164
165#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
166pub enum AdtDef {
167 Struct(Struct),
168 Enum(Enum),
169}
170impl_froms!(AdtDef: Struct, Enum);
171
172impl AdtDef {
173 fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
174 match self {
175 AdtDef::Struct(s) => s.module(db),
176 AdtDef::Enum(e) => e.module(db),
177 }
178 .krate(db)
179 }
180}
181
182/// A type. This is based on the `TyKind` enum in rustc (librustc/ty/sty.rs). 165/// A type. This is based on the `TyKind` enum in rustc (librustc/ty/sty.rs).
183/// 166///
184/// This should be cheap to clone. 167/// This should be cheap to clone.