diff options
author | Ville Penttinen <[email protected]> | 2019-02-25 07:27:47 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-02-25 08:51:46 +0000 |
commit | 18b0bd9bffeeeaf664f4a21894d5bfff51e82b32 (patch) | |
tree | de8c51b51b8324d6566143e7b73997c4c61a3f70 /crates/ra_hir/src/code_model_api.rs | |
parent | 7ffff9c74caae108db53366e3b90857b7c405c6c (diff) |
Add const type inference
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 278407504..9efd902fa 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -554,11 +554,26 @@ impl Const { | |||
554 | self.id.module(db) | 554 | self.id.module(db) |
555 | } | 555 | } |
556 | 556 | ||
557 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { | ||
558 | db.const_signature(*self) | ||
559 | } | ||
560 | |||
557 | /// The containing impl block, if this is a method. | 561 | /// The containing impl block, if this is a method. |
558 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | 562 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { |
559 | let module_impls = db.impls_in_module(self.module(db)); | 563 | let module_impls = db.impls_in_module(self.module(db)); |
560 | ImplBlock::containing(module_impls, (*self).into()) | 564 | ImplBlock::containing(module_impls, (*self).into()) |
561 | } | 565 | } |
566 | |||
567 | // TODO: move to a more general type for 'body-having' items | ||
568 | /// Builds a resolver for code inside this item. | ||
569 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | ||
570 | // take the outer scope... | ||
571 | let r = self | ||
572 | .impl_block(db) | ||
573 | .map(|ib| ib.resolver(db)) | ||
574 | .unwrap_or_else(|| self.module(db).resolver(db)); | ||
575 | r | ||
576 | } | ||
562 | } | 577 | } |
563 | 578 | ||
564 | impl Docs for Const { | 579 | impl Docs for Const { |
@@ -567,6 +582,23 @@ impl Docs for Const { | |||
567 | } | 582 | } |
568 | } | 583 | } |
569 | 584 | ||
585 | /// The declared signature of a const. | ||
586 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
587 | pub struct ConstSignature { | ||
588 | pub(crate) name: Name, | ||
589 | pub(crate) type_ref: TypeRef, | ||
590 | } | ||
591 | |||
592 | impl ConstSignature { | ||
593 | pub fn name(&self) -> &Name { | ||
594 | &self.name | ||
595 | } | ||
596 | |||
597 | pub fn type_ref(&self) -> &TypeRef { | ||
598 | &self.type_ref | ||
599 | } | ||
600 | } | ||
601 | |||
570 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 602 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
571 | pub struct Static { | 603 | pub struct Static { |
572 | pub(crate) id: StaticId, | 604 | pub(crate) id: StaticId, |