diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/attr.rs | 1 | ||||
-rw-r--r-- | crates/hir_def/src/nameres.rs | 12 |
2 files changed, 11 insertions, 2 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index 1b09ff816..c72649c41 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -207,6 +207,7 @@ impl Attrs { | |||
207 | mod_data.definition_source(db).as_ref().map(|src| match src { | 207 | mod_data.definition_source(db).as_ref().map(|src| match src { |
208 | ModuleSource::SourceFile(file) => file as &dyn AttrsOwner, | 208 | ModuleSource::SourceFile(file) => file as &dyn AttrsOwner, |
209 | ModuleSource::Module(module) => module as &dyn AttrsOwner, | 209 | ModuleSource::Module(module) => module as &dyn AttrsOwner, |
210 | ModuleSource::BlockExpr(block) => block as &dyn AttrsOwner, | ||
210 | }), | 211 | }), |
211 | ), | 212 | ), |
212 | } | 213 | } |
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 23f960ad4..a3200c710 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -109,6 +109,10 @@ pub enum ModuleOrigin { | |||
109 | Inline { | 109 | Inline { |
110 | definition: AstId<ast::Module>, | 110 | definition: AstId<ast::Module>, |
111 | }, | 111 | }, |
112 | /// Pseudo-module introduced by a block scope (contains only inner items). | ||
113 | BlockExpr { | ||
114 | block: AstId<ast::BlockExpr>, | ||
115 | }, | ||
112 | } | 116 | } |
113 | 117 | ||
114 | impl Default for ModuleOrigin { | 118 | impl Default for ModuleOrigin { |
@@ -122,7 +126,7 @@ impl ModuleOrigin { | |||
122 | match self { | 126 | match self { |
123 | ModuleOrigin::File { declaration: module, .. } | 127 | ModuleOrigin::File { declaration: module, .. } |
124 | | ModuleOrigin::Inline { definition: module, .. } => Some(*module), | 128 | | ModuleOrigin::Inline { definition: module, .. } => Some(*module), |
125 | ModuleOrigin::CrateRoot { .. } => None, | 129 | ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None, |
126 | } | 130 | } |
127 | } | 131 | } |
128 | 132 | ||
@@ -137,7 +141,7 @@ impl ModuleOrigin { | |||
137 | 141 | ||
138 | pub fn is_inline(&self) -> bool { | 142 | pub fn is_inline(&self) -> bool { |
139 | match self { | 143 | match self { |
140 | ModuleOrigin::Inline { .. } => true, | 144 | ModuleOrigin::Inline { .. } | ModuleOrigin::BlockExpr { .. } => true, |
141 | ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false, | 145 | ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false, |
142 | } | 146 | } |
143 | } | 147 | } |
@@ -155,6 +159,9 @@ impl ModuleOrigin { | |||
155 | definition.file_id, | 159 | definition.file_id, |
156 | ModuleSource::Module(definition.to_node(db.upcast())), | 160 | ModuleSource::Module(definition.to_node(db.upcast())), |
157 | ), | 161 | ), |
162 | ModuleOrigin::BlockExpr { block } => { | ||
163 | InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db.upcast()))) | ||
164 | } | ||
158 | } | 165 | } |
159 | } | 166 | } |
160 | } | 167 | } |
@@ -300,6 +307,7 @@ impl ModuleData { | |||
300 | pub enum ModuleSource { | 307 | pub enum ModuleSource { |
301 | SourceFile(ast::SourceFile), | 308 | SourceFile(ast::SourceFile), |
302 | Module(ast::Module), | 309 | Module(ast::Module), |
310 | BlockExpr(ast::BlockExpr), | ||
303 | } | 311 | } |
304 | 312 | ||
305 | mod diagnostics { | 313 | mod diagnostics { |