aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 21:50:08 +0000
committerAleksey Kladov <[email protected]>2019-01-24 21:50:08 +0000
commit1db2cbcb8bd61b4f19f61cc6319343e5ad894515 (patch)
tree1769ced52f4e298773b8fee9fab79b691ddb5f04 /crates/ra_hir/src/code_model_api.rs
parentf588535273db261c32e23c1b0221d03ad82cd94d (diff)
move consts&statics to new id
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 1fa591ea4..d82dda79a 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -16,7 +16,7 @@ use crate::{
16 code_model_impl::def_id_to_ast, 16 code_model_impl::def_id_to_ast,
17 docs::{Documentation, Docs, docs_from_ast}, 17 docs::{Documentation, Docs, docs_from_ast},
18 module_tree::ModuleId, 18 module_tree::ModuleId,
19 ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef}, 19 ids::{FunctionId, StructId, EnumId, EnumVariantId, AstItemDef, ConstId, StaticId},
20}; 20};
21 21
22/// hir::Crate describes a single crate. It's the main interface with which 22/// hir::Crate describes a single crate. It's the main interface with which
@@ -47,8 +47,6 @@ impl Crate {
47 47
48#[derive(Debug)] 48#[derive(Debug)]
49pub enum Def { 49pub enum Def {
50 Const(Const),
51 Static(Static),
52 Trait(Trait), 50 Trait(Trait),
53 Type(Type), 51 Type(Type),
54 Item, 52 Item,
@@ -67,11 +65,21 @@ pub enum ModuleDef {
67 Function(Function), 65 Function(Function),
68 Struct(Struct), 66 Struct(Struct),
69 Enum(Enum), 67 Enum(Enum),
70 // Can't be directly declared, but can be imported.
71 EnumVariant(EnumVariant), 68 EnumVariant(EnumVariant),
69 Const(Const),
70 Static(Static),
71 // Can't be directly declared, but can be imported.
72 Def(DefId), 72 Def(DefId),
73} 73}
74impl_froms!(ModuleDef: Module, Function, Struct, Enum, EnumVariant); 74impl_froms!(
75 ModuleDef: Module,
76 Function,
77 Struct,
78 Enum,
79 EnumVariant,
80 Const,
81 Static
82);
75 83
76impl From<DefId> for ModuleDef { 84impl From<DefId> for ModuleDef {
77 fn from(it: DefId) -> ModuleDef { 85 fn from(it: DefId) -> ModuleDef {
@@ -386,18 +394,14 @@ impl Docs for Function {
386 } 394 }
387} 395}
388 396
389#[derive(Debug, Clone, PartialEq, Eq, Hash)] 397#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
390pub struct Const { 398pub struct Const {
391 pub(crate) def_id: DefId, 399 pub(crate) id: ConstId,
392} 400}
393 401
394impl Const { 402impl Const {
395 pub(crate) fn new(def_id: DefId) -> Const {
396 Const { def_id }
397 }
398
399 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 403 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
400 def_id_to_ast(db, self.def_id) 404 self.id.source(db)
401 } 405 }
402} 406}
403 407
@@ -407,18 +411,14 @@ impl Docs for Const {
407 } 411 }
408} 412}
409 413
410#[derive(Debug, Clone, PartialEq, Eq, Hash)] 414#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
411pub struct Static { 415pub struct Static {
412 pub(crate) def_id: DefId, 416 pub(crate) id: StaticId,
413} 417}
414 418
415impl Static { 419impl Static {
416 pub(crate) fn new(def_id: DefId) -> Static {
417 Static { def_id }
418 }
419
420 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 420 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
421 def_id_to_ast(db, self.def_id) 421 self.id.source(db)
422 } 422 }
423} 423}
424 424