@@ -60,7 +60,7 @@ mod tests;
60
60
use std:: { cmp:: Ord , ops:: Deref } ;
61
61
62
62
use 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 } ;
64
64
use itertools:: Itertools ;
65
65
use la_arena:: Arena ;
66
66
use profile:: Count ;
@@ -217,13 +217,13 @@ pub enum ModuleOrigin {
217
217
/// Note that non-inline modules, by definition, live inside non-macro file.
218
218
File {
219
219
is_mod_rs : bool ,
220
- declaration : AstId < ast:: Module > ,
220
+ declaration : FileAstId < ast:: Module > ,
221
221
declaration_tree_id : ItemTreeId < Mod > ,
222
222
definition : FileId ,
223
223
} ,
224
224
Inline {
225
225
definition_tree_id : ItemTreeId < Mod > ,
226
- definition : AstId < ast:: Module > ,
226
+ definition : FileAstId < ast:: Module > ,
227
227
} ,
228
228
/// Pseudo-module introduced by a block scope (contains only inner items).
229
229
BlockExpr {
@@ -235,8 +235,12 @@ pub enum ModuleOrigin {
235
235
impl ModuleOrigin {
236
236
pub fn declaration ( & self ) -> Option < AstId < ast:: Module > > {
237
237
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
+ }
240
244
ModuleOrigin :: CrateRoot { .. } | ModuleOrigin :: BlockExpr { .. } => None ,
241
245
}
242
246
}
@@ -261,14 +265,15 @@ impl ModuleOrigin {
261
265
/// That is, a file or a `mod foo {}` with items.
262
266
fn definition_source ( & self , db : & dyn DefDatabase ) -> InFile < ModuleSource > {
263
267
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) )
268
271
}
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
+ ) ,
272
277
) ,
273
278
ModuleOrigin :: BlockExpr { block, .. } => {
274
279
InFile :: new ( block. file_id , ModuleSource :: BlockExpr ( block. to_node ( db. upcast ( ) ) ) )
@@ -645,7 +650,7 @@ impl ModuleData {
645
650
ModuleOrigin :: File { definition, .. } | ModuleOrigin :: CrateRoot { definition } => {
646
651
definition. into ( )
647
652
}
648
- ModuleOrigin :: Inline { definition , .. } => definition . file_id ,
653
+ ModuleOrigin :: Inline { definition_tree_id , .. } => definition_tree_id . file_id ( ) ,
649
654
ModuleOrigin :: BlockExpr { block, .. } => block. file_id ,
650
655
}
651
656
}
0 commit comments