From 82146737acc74b2483f39f1dd0ae4dfffcfda824 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 20 Jan 2021 20:05:48 +0100 Subject: Treat BlockExpr as a potential module origin --- crates/hir_def/src/attr.rs | 1 + crates/hir_def/src/nameres.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'crates/hir_def') 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 { mod_data.definition_source(db).as_ref().map(|src| match src { ModuleSource::SourceFile(file) => file as &dyn AttrsOwner, ModuleSource::Module(module) => module as &dyn AttrsOwner, + ModuleSource::BlockExpr(block) => block as &dyn AttrsOwner, }), ), } 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 { Inline { definition: AstId, }, + /// Pseudo-module introduced by a block scope (contains only inner items). + BlockExpr { + block: AstId, + }, } impl Default for ModuleOrigin { @@ -122,7 +126,7 @@ impl ModuleOrigin { match self { ModuleOrigin::File { declaration: module, .. } | ModuleOrigin::Inline { definition: module, .. } => Some(*module), - ModuleOrigin::CrateRoot { .. } => None, + ModuleOrigin::CrateRoot { .. } | ModuleOrigin::BlockExpr { .. } => None, } } @@ -137,7 +141,7 @@ impl ModuleOrigin { pub fn is_inline(&self) -> bool { match self { - ModuleOrigin::Inline { .. } => true, + ModuleOrigin::Inline { .. } | ModuleOrigin::BlockExpr { .. } => true, ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false, } } @@ -155,6 +159,9 @@ impl ModuleOrigin { definition.file_id, ModuleSource::Module(definition.to_node(db.upcast())), ), + ModuleOrigin::BlockExpr { block } => { + InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db.upcast()))) + } } } } @@ -300,6 +307,7 @@ impl ModuleData { pub enum ModuleSource { SourceFile(ast::SourceFile), Module(ast::Module), + BlockExpr(ast::BlockExpr), } mod diagnostics { -- cgit v1.2.3