|
86 | 86 | //! syntax nodes against this specific crate. |
87 | 87 |
|
88 | 88 | use base_db::FileId; |
| 89 | +use either::Either; |
89 | 90 | use hir_def::{ |
90 | 91 | child_by_source::ChildBySource, |
91 | 92 | dyn_map::{ |
92 | 93 | keys::{self, Key}, |
93 | 94 | DynMap, |
94 | 95 | }, |
95 | 96 | hir::{BindingId, LabelId}, |
96 | | - AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, FieldId, |
97 | | - FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, |
98 | | - StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, UseId, VariantId, |
| 97 | + AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternCrateId, |
| 98 | + FieldId, FunctionId, GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, |
| 99 | + StaticId, StructId, TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, UseId, VariantId, |
99 | 100 | }; |
100 | 101 | use hir_expand::{attrs::AttrId, name::AsName, HirFileId, HirFileIdExt, MacroCallId}; |
101 | 102 | use rustc_hash::FxHashMap; |
@@ -131,15 +132,19 @@ impl SourceToDefCtx<'_, '_> { |
131 | 132 | mods |
132 | 133 | } |
133 | 134 |
|
134 | | - pub(super) fn module_to_def(&self, src: InFile<ast::Module>) -> Option<ModuleId> { |
| 135 | + pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { |
135 | 136 | let _p = tracing::span!(tracing::Level::INFO, "module_to_def"); |
136 | 137 | let parent_declaration = src |
137 | 138 | .syntax() |
138 | 139 | .ancestors_with_macros_skip_attr_item(self.db.upcast()) |
139 | | - .find_map(|it| it.map(ast::Module::cast).transpose()); |
| 140 | + .find_map(|it| it.map(Either::<ast::Module, ast::BlockExpr>::cast).transpose()) |
| 141 | + .map(|it| it.transpose()); |
140 | 142 |
|
141 | 143 | let parent_module = match parent_declaration { |
142 | | - Some(parent_declaration) => self.module_to_def(parent_declaration), |
| 144 | + Some(Either::Right(parent_block)) => self |
| 145 | + .block_to_def(parent_block) |
| 146 | + .map(|block| self.db.block_def_map(block).root_module_id()), |
| 147 | + Some(Either::Left(parent_declaration)) => self.module_to_def(parent_declaration), |
143 | 148 | None => { |
144 | 149 | let file_id = src.file_id.original_file(self.db.upcast()); |
145 | 150 | self.file_to_def(file_id).first().copied() |
@@ -197,6 +202,9 @@ impl SourceToDefCtx<'_, '_> { |
197 | 202 | pub(super) fn tuple_field_to_def(&mut self, src: InFile<ast::TupleField>) -> Option<FieldId> { |
198 | 203 | self.to_def(src, keys::TUPLE_FIELD) |
199 | 204 | } |
| 205 | + pub(super) fn block_to_def(&mut self, src: InFile<ast::BlockExpr>) -> Option<BlockId> { |
| 206 | + self.to_def(src, keys::BLOCK) |
| 207 | + } |
200 | 208 | pub(super) fn enum_variant_to_def( |
201 | 209 | &mut self, |
202 | 210 | src: InFile<ast::Variant>, |
|
0 commit comments