diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index d82dda79a..e2979617d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -13,10 +13,9 @@ use crate::{ | |||
13 | ty::{InferenceResult, VariantDef}, | 13 | ty::{InferenceResult, VariantDef}, |
14 | adt::VariantData, | 14 | adt::VariantData, |
15 | generics::GenericParams, | 15 | generics::GenericParams, |
16 | code_model_impl::def_id_to_ast, | ||
17 | docs::{Documentation, Docs, docs_from_ast}, | 16 | docs::{Documentation, Docs, docs_from_ast}, |
18 | module_tree::ModuleId, | 17 | module_tree::ModuleId, |
19 | ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef, ConstId, StaticId}, | 18 | ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef, ConstId, StaticId, TraitId, TypeId}, |
20 | }; | 19 | }; |
21 | 20 | ||
22 | /// hir::Crate describes a single crate. It's the main interface with which | 21 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -47,8 +46,6 @@ impl Crate { | |||
47 | 46 | ||
48 | #[derive(Debug)] | 47 | #[derive(Debug)] |
49 | pub enum Def { | 48 | pub enum Def { |
50 | Trait(Trait), | ||
51 | Type(Type), | ||
52 | Item, | 49 | Item, |
53 | } | 50 | } |
54 | 51 | ||
@@ -68,6 +65,8 @@ pub enum ModuleDef { | |||
68 | EnumVariant(EnumVariant), | 65 | EnumVariant(EnumVariant), |
69 | Const(Const), | 66 | Const(Const), |
70 | Static(Static), | 67 | Static(Static), |
68 | Trait(Trait), | ||
69 | Type(Type), | ||
71 | // Can't be directly declared, but can be imported. | 70 | // Can't be directly declared, but can be imported. |
72 | Def(DefId), | 71 | Def(DefId), |
73 | } | 72 | } |
@@ -78,7 +77,9 @@ impl_froms!( | |||
78 | Enum, | 77 | Enum, |
79 | EnumVariant, | 78 | EnumVariant, |
80 | Const, | 79 | Const, |
81 | Static | 80 | Static, |
81 | Trait, | ||
82 | Type | ||
82 | ); | 83 | ); |
83 | 84 | ||
84 | impl From<DefId> for ModuleDef { | 85 | impl From<DefId> for ModuleDef { |
@@ -428,22 +429,18 @@ impl Docs for Static { | |||
428 | } | 429 | } |
429 | } | 430 | } |
430 | 431 | ||
431 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 432 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
432 | pub struct Trait { | 433 | pub struct Trait { |
433 | pub(crate) def_id: DefId, | 434 | pub(crate) id: TraitId, |
434 | } | 435 | } |
435 | 436 | ||
436 | impl Trait { | 437 | impl Trait { |
437 | pub(crate) fn new(def_id: DefId) -> Trait { | ||
438 | Trait { def_id } | ||
439 | } | ||
440 | |||
441 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { | 438 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { |
442 | def_id_to_ast(db, self.def_id) | 439 | self.id.source(db) |
443 | } | 440 | } |
444 | 441 | ||
445 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 442 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
446 | db.generic_params(self.def_id.into()) | 443 | db.generic_params((*self).into()) |
447 | } | 444 | } |
448 | } | 445 | } |
449 | 446 | ||
@@ -453,22 +450,18 @@ impl Docs for Trait { | |||
453 | } | 450 | } |
454 | } | 451 | } |
455 | 452 | ||
456 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 453 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
457 | pub struct Type { | 454 | pub struct Type { |
458 | pub(crate) def_id: DefId, | 455 | pub(crate) id: TypeId, |
459 | } | 456 | } |
460 | 457 | ||
461 | impl Type { | 458 | impl Type { |
462 | pub(crate) fn new(def_id: DefId) -> Type { | ||
463 | Type { def_id } | ||
464 | } | ||
465 | |||
466 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) { | 459 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) { |
467 | def_id_to_ast(db, self.def_id) | 460 | self.id.source(db) |
468 | } | 461 | } |
469 | 462 | ||
470 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 463 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
471 | db.generic_params(self.def_id.into()) | 464 | db.generic_params((*self).into()) |
472 | } | 465 | } |
473 | } | 466 | } |
474 | 467 | ||