From 5ca71a19903cea277ed8a347b36cffeca6b99922 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 13 Jun 2021 13:00:34 +0200 Subject: Make block-local trait impls work As long as either the trait or the implementing type are defined in the same block. --- crates/hir_def/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index 303083c6d..bb174aec8 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs @@ -112,6 +112,10 @@ impl ModuleId { self.def_map(db).containing_module(self.local_id) } + pub fn containing_block(&self) -> Option { + self.block + } + /// Returns `true` if this module represents a block expression. /// /// Returns `false` if this module is a submodule *inside* a block expression @@ -581,6 +585,18 @@ impl HasModule for GenericDefId { } } +impl HasModule for TypeAliasId { + fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { + self.lookup(db).module(db) + } +} + +impl HasModule for TraitId { + fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { + self.lookup(db).container + } +} + impl HasModule for StaticLoc { fn module(&self, _db: &dyn db::DefDatabase) -> ModuleId { self.container -- cgit v1.2.3