aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model_api.rs112
1 files changed, 56 insertions, 56 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 4447c608a..b6834bc25 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -533,16 +533,16 @@ pub enum DefWithBody {
533impl_froms!(DefWithBody: Function, Const, Static); 533impl_froms!(DefWithBody: Function, Const, Static);
534 534
535impl DefWithBody { 535impl DefWithBody {
536 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 536 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
537 db.infer(*self) 537 db.infer(self)
538 } 538 }
539 539
540 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 540 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
541 db.body_hir(*self) 541 db.body_hir(self)
542 } 542 }
543 543
544 pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 544 pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
545 db.body_with_source_map(*self).1 545 db.body_with_source_map(self).1
546 } 546 }
547 547
548 /// Builds a resolver for code inside this item. 548 /// Builds a resolver for code inside this item.
@@ -592,50 +592,50 @@ impl FnSignature {
592} 592}
593 593
594impl Function { 594impl Function {
595 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 595 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
596 self.id.source(db) 596 self.id.source(db)
597 } 597 }
598 598
599 pub fn module(&self, db: &impl DefDatabase) -> Module { 599 pub fn module(self, db: &impl DefDatabase) -> Module {
600 self.id.module(db) 600 self.id.module(db)
601 } 601 }
602 602
603 pub fn name(&self, db: &impl HirDatabase) -> Name { 603 pub fn name(self, db: &impl HirDatabase) -> Name {
604 self.signature(db).name.clone() 604 self.signature(db).name.clone()
605 } 605 }
606 606
607 pub(crate) fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> { 607 pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
608 db.body_with_source_map((*self).into()).1 608 db.body_with_source_map(self.into()).1
609 } 609 }
610 610
611 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 611 pub fn body(self, db: &impl HirDatabase) -> Arc<Body> {
612 db.body_hir((*self).into()) 612 db.body_hir(self.into())
613 } 613 }
614 614
615 pub fn ty(&self, db: &impl HirDatabase) -> Ty { 615 pub fn ty(self, db: &impl HirDatabase) -> Ty {
616 db.type_for_def((*self).into(), Namespace::Values) 616 db.type_for_def(self.into(), Namespace::Values)
617 } 617 }
618 618
619 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { 619 pub fn signature(self, db: &impl HirDatabase) -> Arc<FnSignature> {
620 db.fn_signature(*self) 620 db.fn_signature(self)
621 } 621 }
622 622
623 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 623 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
624 db.infer((*self).into()) 624 db.infer(self.into())
625 } 625 }
626 626
627 /// The containing impl block, if this is a method. 627 /// The containing impl block, if this is a method.
628 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 628 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
629 let module_impls = db.impls_in_module(self.module(db)); 629 let module_impls = db.impls_in_module(self.module(db));
630 ImplBlock::containing(module_impls, (*self).into()) 630 ImplBlock::containing(module_impls, self.into())
631 } 631 }
632 632
633 /// The containing trait, if this is a trait method definition. 633 /// The containing trait, if this is a trait method definition.
634 pub fn parent_trait(&self, db: &impl DefDatabase) -> Option<Trait> { 634 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
635 db.trait_items_index(self.module(db)).get_parent_trait((*self).into()) 635 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
636 } 636 }
637 637
638 pub fn container(&self, db: &impl DefDatabase) -> Option<Container> { 638 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
639 if let Some(impl_block) = self.impl_block(db) { 639 if let Some(impl_block) = self.impl_block(db) {
640 Some(impl_block.into()) 640 Some(impl_block.into())
641 } else if let Some(trait_) = self.parent_trait(db) { 641 } else if let Some(trait_) = self.parent_trait(db) {
@@ -647,7 +647,7 @@ impl Function {
647 647
648 // FIXME: move to a more general type for 'body-having' items 648 // FIXME: move to a more general type for 'body-having' items
649 /// Builds a resolver for code inside this item. 649 /// Builds a resolver for code inside this item.
650 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 650 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
651 // take the outer scope... 651 // take the outer scope...
652 let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db)); 652 let r = self.container(db).map_or_else(|| self.module(db).resolver(db), |c| c.resolver(db));
653 // ...and add generic params, if present 653 // ...and add generic params, if present
@@ -656,10 +656,10 @@ impl Function {
656 r 656 r
657 } 657 }
658 658
659 pub fn diagnostics(&self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { 659 pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) {
660 let infer = self.infer(db); 660 let infer = self.infer(db);
661 infer.add_diagnostics(db, *self, sink); 661 infer.add_diagnostics(db, self, sink);
662 let mut validator = ExprValidator::new(*self, infer, sink); 662 let mut validator = ExprValidator::new(self, infer, sink);
663 validator.validate_body(db); 663 validator.validate_body(db);
664 } 664 }
665} 665}
@@ -676,31 +676,31 @@ pub struct Const {
676} 676}
677 677
678impl Const { 678impl Const {
679 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 679 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
680 self.id.source(db) 680 self.id.source(db)
681 } 681 }
682 682
683 pub fn module(&self, db: &impl DefDatabase) -> Module { 683 pub fn module(self, db: &impl DefDatabase) -> Module {
684 self.id.module(db) 684 self.id.module(db)
685 } 685 }
686 686
687 pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { 687 pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
688 db.const_signature(*self) 688 db.const_signature(self)
689 } 689 }
690 690
691 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 691 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
692 db.infer((*self).into()) 692 db.infer(self.into())
693 } 693 }
694 694
695 /// The containing impl block, if this is a method. 695 /// The containing impl block, if this is a method.
696 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 696 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
697 let module_impls = db.impls_in_module(self.module(db)); 697 let module_impls = db.impls_in_module(self.module(db));
698 ImplBlock::containing(module_impls, (*self).into()) 698 ImplBlock::containing(module_impls, self.into())
699 } 699 }
700 700
701 // FIXME: move to a more general type for 'body-having' items 701 // FIXME: move to a more general type for 'body-having' items
702 /// Builds a resolver for code inside this item. 702 /// Builds a resolver for code inside this item.
703 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 703 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
704 // take the outer scope... 704 // take the outer scope...
705 let r = self 705 let r = self
706 .impl_block(db) 706 .impl_block(db)
@@ -739,26 +739,26 @@ pub struct Static {
739} 739}
740 740
741impl Static { 741impl Static {
742 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 742 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
743 self.id.source(db) 743 self.id.source(db)
744 } 744 }
745 745
746 pub fn module(&self, db: &impl DefDatabase) -> Module { 746 pub fn module(self, db: &impl DefDatabase) -> Module {
747 self.id.module(db) 747 self.id.module(db)
748 } 748 }
749 749
750 pub fn signature(&self, db: &impl HirDatabase) -> Arc<ConstSignature> { 750 pub fn signature(self, db: &impl HirDatabase) -> Arc<ConstSignature> {
751 db.static_signature(*self) 751 db.static_signature(self)
752 } 752 }
753 753
754 /// Builds a resolver for code inside this item. 754 /// Builds a resolver for code inside this item.
755 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 755 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
756 // take the outer scope... 756 // take the outer scope...
757 self.module(db).resolver(db) 757 self.module(db).resolver(db)
758 } 758 }
759 759
760 pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> { 760 pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> {
761 db.infer((*self).into()) 761 db.infer(self.into())
762 } 762 }
763} 763}
764 764
@@ -774,11 +774,11 @@ pub struct Trait {
774} 774}
775 775
776impl Trait { 776impl Trait {
777 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 777 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
778 self.id.source(db) 778 self.id.source(db)
779 } 779 }
780 780
781 pub fn module(&self, db: &impl DefDatabase) -> Module { 781 pub fn module(self, db: &impl DefDatabase) -> Module {
782 self.id.module(db) 782 self.id.module(db)
783 } 783 }
784 784
@@ -802,7 +802,7 @@ impl Trait {
802 self.trait_data(db).is_auto() 802 self.trait_data(db).is_auto()
803 } 803 }
804 804
805 pub(crate) fn resolver(&self, db: &impl DefDatabase) -> Resolver { 805 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
806 let r = self.module(db).resolver(db); 806 let r = self.module(db).resolver(db);
807 // add generic params, if present 807 // add generic params, if present
808 let p = self.generic_params(db); 808 let p = self.generic_params(db);
@@ -823,26 +823,26 @@ pub struct TypeAlias {
823} 823}
824 824
825impl TypeAlias { 825impl TypeAlias {
826 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) { 826 pub fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
827 self.id.source(db) 827 self.id.source(db)
828 } 828 }
829 829
830 pub fn module(&self, db: &impl DefDatabase) -> Module { 830 pub fn module(self, db: &impl DefDatabase) -> Module {
831 self.id.module(db) 831 self.id.module(db)
832 } 832 }
833 833
834 /// The containing impl block, if this is a method. 834 /// The containing impl block, if this is a method.
835 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> { 835 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
836 let module_impls = db.impls_in_module(self.module(db)); 836 let module_impls = db.impls_in_module(self.module(db));
837 ImplBlock::containing(module_impls, (*self).into()) 837 ImplBlock::containing(module_impls, self.into())
838 } 838 }
839 839
840 /// The containing trait, if this is a trait method definition. 840 /// The containing trait, if this is a trait method definition.
841 pub fn parent_trait(&self, db: &impl DefDatabase) -> Option<Trait> { 841 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
842 db.trait_items_index(self.module(db)).get_parent_trait((*self).into()) 842 db.trait_items_index(self.module(db)).get_parent_trait(self.into())
843 } 843 }
844 844
845 pub fn container(&self, db: &impl DefDatabase) -> Option<Container> { 845 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
846 if let Some(impl_block) = self.impl_block(db) { 846 if let Some(impl_block) = self.impl_block(db) {
847 Some(impl_block.into()) 847 Some(impl_block.into())
848 } else if let Some(trait_) = self.parent_trait(db) { 848 } else if let Some(trait_) = self.parent_trait(db) {
@@ -857,7 +857,7 @@ impl TypeAlias {
857 } 857 }
858 858
859 /// Builds a resolver for the type references in this type alias. 859 /// Builds a resolver for the type references in this type alias.
860 pub(crate) fn resolver(&self, db: &impl HirDatabase) -> Resolver { 860 pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
861 // take the outer scope... 861 // take the outer scope...
862 let r = self 862 let r = self
863 .impl_block(db) 863 .impl_block(db)
@@ -883,7 +883,7 @@ pub enum Container {
883impl_froms!(Container: Trait, ImplBlock); 883impl_froms!(Container: Trait, ImplBlock);
884 884
885impl Container { 885impl Container {
886 pub(crate) fn resolver(&self, db: &impl DefDatabase) -> Resolver { 886 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
887 match self { 887 match self {
888 Container::Trait(trait_) => trait_.resolver(db), 888 Container::Trait(trait_) => trait_.resolver(db),
889 Container::ImplBlock(impl_block) => impl_block.resolver(db), 889 Container::ImplBlock(impl_block) => impl_block.resolver(db),