Fix: Handle block exprs as modules when finding their parents

This commit is contained in:
Shoyu Vanilla 2024-09-29 16:19:44 +09:00
parent 28830ff2f1
commit e09c2a08d7
4 changed files with 46 additions and 7 deletions

View file

@ -497,10 +497,9 @@ impl Module {
/// Finds a parent module.
pub fn parent(self, db: &dyn HirDatabase) -> Option<Module> {
// FIXME: handle block expressions as modules (their parent is in a different DefMap)
let def_map = self.id.def_map(db.upcast());
let parent_id = def_map[self.id.local_id].parent?;
Some(Module { id: def_map.module_id(parent_id) })
let parent_id = def_map.containing_module(self.id.local_id)?;
Some(Module { id: parent_id })
}
/// Finds nearest non-block ancestor `Module` (`self` included).