aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-17 13:56:22 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-17 13:56:22 +0000
commitf937d11ad892036fa93b25a2c19d10dcebe4ab24 (patch)
tree71f3719509f3fb46f5d2ce5a93da42ea67b23b70 /crates/ra_hir/src/code_model_api.rs
parentedd4c1d8a6c270fe39ae881c23c722c658c87c32 (diff)
parent3c7c7e5a04306f8b68dffef2b5ca84628ed81ce2 (diff)
Merge #843
843: Impl generics r=matklad a=flodiebold This handles type parameters on impls when typing method calls. ~One remaining problem is that the autoderefs aren't applied during the unification of the method receiver type with the actual receiver type, which means that the type parameters are only correctly inferred if no autoderefs happened.~ Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 99f004905..26ebc445b 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -463,7 +463,7 @@ impl Function {
463 self.id.source(db) 463 self.id.source(db)
464 } 464 }
465 465
466 pub fn module(&self, db: &impl HirDatabase) -> Module { 466 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
467 self.id.module(db) 467 self.id.module(db)
468 } 468 }
469 469
@@ -497,6 +497,12 @@ impl Function {
497 db.generic_params((*self).into()) 497 db.generic_params((*self).into())
498 } 498 }
499 499
500 /// The containing impl block, if this is a method.
501 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
502 let module_impls = db.impls_in_module(self.module(db));
503 ImplBlock::containing(module_impls, (*self).into())
504 }
505
500 // TODO: move to a more general type for 'body-having' items 506 // TODO: move to a more general type for 'body-having' items
501 /// Builds a resolver for code inside this item. 507 /// Builds a resolver for code inside this item.
502 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 508 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
@@ -527,6 +533,16 @@ impl Const {
527 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 533 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
528 self.id.source(db) 534 self.id.source(db)
529 } 535 }
536
537 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
538 self.id.module(db)
539 }
540
541 /// The containing impl block, if this is a method.
542 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
543 let module_impls = db.impls_in_module(self.module(db));
544 ImplBlock::containing(module_impls, (*self).into())
545 }
530} 546}
531 547
532impl Docs for Const { 548impl Docs for Const {
@@ -544,6 +560,10 @@ impl Static {
544 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 560 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
545 self.id.source(db) 561 self.id.source(db)
546 } 562 }
563
564 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
565 self.id.module(db)
566 }
547} 567}
548 568
549impl Docs for Static { 569impl Docs for Static {
@@ -562,6 +582,10 @@ impl Trait {
562 self.id.source(db) 582 self.id.source(db)
563 } 583 }
564 584
585 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
586 self.id.module(db)
587 }
588
565 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 589 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
566 db.generic_params((*self).into()) 590 db.generic_params((*self).into())
567 } 591 }
@@ -586,6 +610,16 @@ impl Type {
586 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 610 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
587 db.generic_params((*self).into()) 611 db.generic_params((*self).into())
588 } 612 }
613
614 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module {
615 self.id.module(db)
616 }
617
618 /// The containing impl block, if this is a method.
619 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> {
620 let module_impls = db.impls_in_module(self.module(db));
621 ImplBlock::containing(module_impls, (*self).into())
622 }
589} 623}
590 624
591impl Docs for Type { 625impl Docs for Type {