diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-25 12:03:57 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-25 12:03:57 +0000 |
commit | 7c9acf2f834c582d9cad4f7d0679a0697c591432 (patch) | |
tree | 5829e5a0e4567c532a5d430ed9406a8cd072f5ca /crates/ra_hir/src/code_model_api.rs | |
parent | 4f67df904252c5fbbf3b892bb2e8405778bc904a (diff) | |
parent | cff9a7dfadc6069bbc7b49c3ceb8497c78d426ab (diff) |
Merge #897
897: Add basic const/static type inference r=flodiebold a=vipentti
This adds basic const/static type inference discussed in #887.
Currently the inference does not work for const/static declared inside a block. In addition the inference does not work inside the bodies of const/static.
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 9a44aaa43..da0f1ec94 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, |
@@ -580,6 +612,16 @@ impl Static { | |||
580 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | 612 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { |
581 | self.id.module(db) | 613 | self.id.module(db) |
582 | } | 614 | } |
615 | |||
616 | pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { | ||
617 | db.static_signature(*self) | ||
618 | } | ||
619 | |||
620 | /// Builds a resolver for code inside this item. | ||
621 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | ||
622 | // take the outer scope... | ||
623 | self.module(db).resolver(db) | ||
624 | } | ||
583 | } | 625 | } |
584 | 626 | ||
585 | impl Docs for Static { | 627 | impl Docs for Static { |