@@ -60,7 +60,7 @@ mod tests;
6060use std:: { cmp:: Ord , ops:: Deref } ;
6161
6262use base_db:: { CrateId , Edition , FileId , ProcMacroKind } ;
63- use hir_expand:: { name:: Name , HirFileId , InFile , MacroCallId , MacroDefId } ;
63+ use hir_expand:: { ast_id_map :: FileAstId , name:: Name , HirFileId , InFile , MacroCallId , MacroDefId } ;
6464use itertools:: Itertools ;
6565use la_arena:: Arena ;
6666use profile:: Count ;
@@ -217,13 +217,13 @@ pub enum ModuleOrigin {
217217 /// Note that non-inline modules, by definition, live inside non-macro file.
218218 File {
219219 is_mod_rs : bool ,
220- declaration : AstId < ast:: Module > ,
220+ declaration : FileAstId < ast:: Module > ,
221221 declaration_tree_id : ItemTreeId < Mod > ,
222222 definition : FileId ,
223223 } ,
224224 Inline {
225225 definition_tree_id : ItemTreeId < Mod > ,
226- definition : AstId < ast:: Module > ,
226+ definition : FileAstId < ast:: Module > ,
227227 } ,
228228 /// Pseudo-module introduced by a block scope (contains only inner items).
229229 BlockExpr {
@@ -235,8 +235,12 @@ pub enum ModuleOrigin {
235235impl ModuleOrigin {
236236 pub fn declaration ( & self ) -> Option < AstId < ast:: Module > > {
237237 match self {
238- ModuleOrigin :: File { declaration : module, .. }
239- | ModuleOrigin :: Inline { definition : module, .. } => Some ( * module) ,
238+ & ModuleOrigin :: File { declaration, declaration_tree_id, .. } => {
239+ Some ( AstId :: new ( declaration_tree_id. file_id ( ) , declaration) )
240+ }
241+ & ModuleOrigin :: Inline { definition, definition_tree_id } => {
242+ Some ( AstId :: new ( definition_tree_id. file_id ( ) , definition) )
243+ }
240244 ModuleOrigin :: CrateRoot { .. } | ModuleOrigin :: BlockExpr { .. } => None ,
241245 }
242246 }
@@ -261,14 +265,15 @@ impl ModuleOrigin {
261265 /// That is, a file or a `mod foo {}` with items.
262266 fn definition_source ( & self , db : & dyn DefDatabase ) -> InFile < ModuleSource > {
263267 match self {
264- ModuleOrigin :: File { definition, .. } | ModuleOrigin :: CrateRoot { definition } => {
265- let file_id = * definition;
266- let sf = db. parse ( file_id) . tree ( ) ;
267- InFile :: new ( file_id. into ( ) , ModuleSource :: SourceFile ( sf) )
268+ & ModuleOrigin :: File { definition, .. } | & ModuleOrigin :: CrateRoot { definition } => {
269+ let sf = db. parse ( definition) . tree ( ) ;
270+ InFile :: new ( definition. into ( ) , ModuleSource :: SourceFile ( sf) )
268271 }
269- ModuleOrigin :: Inline { definition, .. } => InFile :: new (
270- definition. file_id ,
271- ModuleSource :: Module ( definition. to_node ( db. upcast ( ) ) ) ,
272+ & ModuleOrigin :: Inline { definition, definition_tree_id } => InFile :: new (
273+ definition_tree_id. file_id ( ) ,
274+ ModuleSource :: Module (
275+ AstId :: new ( definition_tree_id. file_id ( ) , definition) . to_node ( db. upcast ( ) ) ,
276+ ) ,
272277 ) ,
273278 ModuleOrigin :: BlockExpr { block, .. } => {
274279 InFile :: new ( block. file_id , ModuleSource :: BlockExpr ( block. to_node ( db. upcast ( ) ) ) )
@@ -645,7 +650,7 @@ impl ModuleData {
645650 ModuleOrigin :: File { definition, .. } | ModuleOrigin :: CrateRoot { definition } => {
646651 definition. into ( )
647652 }
648- ModuleOrigin :: Inline { definition , .. } => definition . file_id ,
653+ ModuleOrigin :: Inline { definition_tree_id , .. } => definition_tree_id . file_id ( ) ,
649654 ModuleOrigin :: BlockExpr { block, .. } => block. file_id ,
650655 }
651656 }
0 commit comments