diff options
Diffstat (limited to 'crates/hir_def/src/lib.rs')
-rw-r--r-- | crates/hir_def/src/lib.rs | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index 987485acc..bb174aec8 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs | |||
@@ -112,6 +112,10 @@ impl ModuleId { | |||
112 | self.def_map(db).containing_module(self.local_id) | 112 | self.def_map(db).containing_module(self.local_id) |
113 | } | 113 | } |
114 | 114 | ||
115 | pub fn containing_block(&self) -> Option<BlockId> { | ||
116 | self.block | ||
117 | } | ||
118 | |||
115 | /// Returns `true` if this module represents a block expression. | 119 | /// Returns `true` if this module represents a block expression. |
116 | /// | 120 | /// |
117 | /// Returns `false` if this module is a submodule *inside* a block expression | 121 | /// Returns `false` if this module is a submodule *inside* a block expression |
@@ -581,6 +585,18 @@ impl HasModule for GenericDefId { | |||
581 | } | 585 | } |
582 | } | 586 | } |
583 | 587 | ||
588 | impl HasModule for TypeAliasId { | ||
589 | fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { | ||
590 | self.lookup(db).module(db) | ||
591 | } | ||
592 | } | ||
593 | |||
594 | impl HasModule for TraitId { | ||
595 | fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { | ||
596 | self.lookup(db).container | ||
597 | } | ||
598 | } | ||
599 | |||
584 | impl HasModule for StaticLoc { | 600 | impl HasModule for StaticLoc { |
585 | fn module(&self, _db: &dyn db::DefDatabase) -> ModuleId { | 601 | fn module(&self, _db: &dyn db::DefDatabase) -> ModuleId { |
586 | self.container | 602 | self.container |
@@ -731,13 +747,11 @@ fn macro_call_as_call_id( | |||
731 | ) | 747 | ) |
732 | .map(MacroCallId::from) | 748 | .map(MacroCallId::from) |
733 | } else { | 749 | } else { |
734 | Ok(def | 750 | Ok(def.as_lazy_macro( |
735 | .as_lazy_macro( | 751 | db.upcast(), |
736 | db.upcast(), | 752 | krate, |
737 | krate, | 753 | MacroCallKind::FnLike { ast_id: call.ast_id, fragment }, |
738 | MacroCallKind::FnLike { ast_id: call.ast_id, fragment }, | 754 | )) |
739 | ) | ||
740 | .into()) | ||
741 | }; | 755 | }; |
742 | Ok(res) | 756 | Ok(res) |
743 | } | 757 | } |
@@ -756,17 +770,15 @@ fn derive_macro_as_call_id( | |||
756 | .segments() | 770 | .segments() |
757 | .last() | 771 | .last() |
758 | .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?; | 772 | .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?; |
759 | let res = def | 773 | let res = def.as_lazy_macro( |
760 | .as_lazy_macro( | 774 | db.upcast(), |
761 | db.upcast(), | 775 | krate, |
762 | krate, | 776 | MacroCallKind::Derive { |
763 | MacroCallKind::Derive { | 777 | ast_id: item_attr.ast_id, |
764 | ast_id: item_attr.ast_id, | 778 | derive_name: last_segment.to_string(), |
765 | derive_name: last_segment.to_string(), | 779 | derive_attr_index: derive_attr.ast_index, |
766 | derive_attr_index: derive_attr.ast_index, | 780 | }, |
767 | }, | 781 | ); |
768 | ) | ||
769 | .into(); | ||
770 | Ok(res) | 782 | Ok(res) |
771 | } | 783 | } |
772 | 784 | ||
@@ -794,17 +806,15 @@ fn attr_macro_as_call_id( | |||
794 | // The parentheses are always disposed here. | 806 | // The parentheses are always disposed here. |
795 | arg.delimiter = None; | 807 | arg.delimiter = None; |
796 | 808 | ||
797 | let res = def | 809 | let res = def.as_lazy_macro( |
798 | .as_lazy_macro( | 810 | db.upcast(), |
799 | db.upcast(), | 811 | krate, |
800 | krate, | 812 | MacroCallKind::Attr { |
801 | MacroCallKind::Attr { | 813 | ast_id: item_attr.ast_id, |
802 | ast_id: item_attr.ast_id, | 814 | attr_name: last_segment.to_string(), |
803 | attr_name: last_segment.to_string(), | 815 | attr_args: arg, |
804 | attr_args: arg, | 816 | invoc_attr_index: macro_attr.id.ast_index, |
805 | invoc_attr_index: macro_attr.id.ast_index, | 817 | }, |
806 | }, | 818 | ); |
807 | ) | ||
808 | .into(); | ||
809 | Ok(res) | 819 | Ok(res) |
810 | } | 820 | } |