@@ -37,8 +37,8 @@ mod tests;
3737
3838use std:: {
3939 fmt:: { self , Debug } ,
40- hash:: { Hash , Hasher } ,
41- ops:: { Index , Range } ,
40+ hash:: Hash ,
41+ ops:: Index ,
4242 sync:: OnceLock ,
4343} ;
4444
@@ -51,7 +51,7 @@ use hir_expand::{
5151 name:: Name ,
5252} ;
5353use intern:: Interned ;
54- use la_arena:: { Arena , Idx , RawIdx } ;
54+ use la_arena:: { Arena , Idx } ;
5555use rustc_hash:: FxHashMap ;
5656use smallvec:: SmallVec ;
5757use span:: { AstIdNode , Edition , FileAstId , SyntaxContext } ;
@@ -277,23 +277,23 @@ struct ItemVisibilities {
277277
278278#[ derive( Default , Debug , Eq , PartialEq ) ]
279279struct ItemTreeData {
280- uses : Arena < Use > ,
281- extern_crates : Arena < ExternCrate > ,
282- extern_blocks : Arena < ExternBlock > ,
283- functions : Arena < Function > ,
284- structs : Arena < Struct > ,
285- unions : Arena < Union > ,
286- enums : Arena < Enum > ,
287- consts : Arena < Const > ,
288- statics : Arena < Static > ,
289- traits : Arena < Trait > ,
290- trait_aliases : Arena < TraitAlias > ,
291- impls : Arena < Impl > ,
292- type_aliases : Arena < TypeAlias > ,
293- mods : Arena < Mod > ,
294- macro_calls : Arena < MacroCall > ,
295- macro_rules : Arena < MacroRules > ,
296- macro_defs : Arena < Macro2 > ,
280+ uses : FxHashMap < ItemTreeAstId < Use > , Use > ,
281+ extern_crates : FxHashMap < ItemTreeAstId < ExternCrate > , ExternCrate > ,
282+ extern_blocks : FxHashMap < ItemTreeAstId < ExternBlock > , ExternBlock > ,
283+ functions : FxHashMap < ItemTreeAstId < Function > , Function > ,
284+ structs : FxHashMap < ItemTreeAstId < Struct > , Struct > ,
285+ unions : FxHashMap < ItemTreeAstId < Union > , Union > ,
286+ enums : FxHashMap < ItemTreeAstId < Enum > , Enum > ,
287+ consts : FxHashMap < ItemTreeAstId < Const > , Const > ,
288+ statics : FxHashMap < ItemTreeAstId < Static > , Static > ,
289+ traits : FxHashMap < ItemTreeAstId < Trait > , Trait > ,
290+ trait_aliases : FxHashMap < ItemTreeAstId < TraitAlias > , TraitAlias > ,
291+ impls : FxHashMap < ItemTreeAstId < Impl > , Impl > ,
292+ type_aliases : FxHashMap < ItemTreeAstId < TypeAlias > , TypeAlias > ,
293+ mods : FxHashMap < ItemTreeAstId < Mod > , Mod > ,
294+ macro_calls : FxHashMap < ItemTreeAstId < MacroCall > , MacroCall > ,
295+ macro_rules : FxHashMap < ItemTreeAstId < MacroRules > , MacroRules > ,
296+ macro_defs : FxHashMap < ItemTreeAstId < Macro2 > , Macro2 > ,
297297
298298 vis : ItemVisibilities ,
299299}
@@ -329,51 +329,11 @@ pub trait ItemTreeNode: Clone {
329329 fn ast_id ( & self ) -> FileAstId < Self :: Source > ;
330330
331331 /// Looks up an instance of `Self` in an item tree.
332- fn lookup ( tree : & ItemTree , index : Idx < Self > ) -> & Self ;
332+ fn lookup ( tree : & ItemTree , index : FileAstId < Self :: Source > ) -> & Self ;
333333}
334334
335- pub struct FileItemTreeId < N > ( Idx < N > ) ;
336-
337- impl < N > FileItemTreeId < N > {
338- pub fn range_iter ( range : Range < Self > ) -> impl Iterator < Item = Self > + Clone {
339- ( range. start . index ( ) . into_raw ( ) . into_u32 ( ) ..range. end . index ( ) . into_raw ( ) . into_u32 ( ) )
340- . map ( RawIdx :: from_u32)
341- . map ( Idx :: from_raw)
342- . map ( Self )
343- }
344- }
345-
346- impl < N > FileItemTreeId < N > {
347- pub fn index ( & self ) -> Idx < N > {
348- self . 0
349- }
350- }
351-
352- impl < N > Clone for FileItemTreeId < N > {
353- fn clone ( & self ) -> Self {
354- * self
355- }
356- }
357- impl < N > Copy for FileItemTreeId < N > { }
358-
359- impl < N > PartialEq for FileItemTreeId < N > {
360- fn eq ( & self , other : & FileItemTreeId < N > ) -> bool {
361- self . 0 == other. 0
362- }
363- }
364- impl < N > Eq for FileItemTreeId < N > { }
365-
366- impl < N > Hash for FileItemTreeId < N > {
367- fn hash < H : Hasher > ( & self , state : & mut H ) {
368- self . 0 . hash ( state)
369- }
370- }
371-
372- impl < N > fmt:: Debug for FileItemTreeId < N > {
373- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
374- self . 0 . fmt ( f)
375- }
376- }
335+ #[ allow( type_alias_bounds) ]
336+ pub type ItemTreeAstId < T : ItemTreeNode > = FileAstId < T :: Source > ;
377337
378338/// Identifies a particular [`ItemTree`].
379339#[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash ) ]
@@ -409,21 +369,21 @@ macro_rules! mod_items {
409369 #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
410370 pub enum ModItem {
411371 $(
412- $typ( FileItemTreeId <$typ >) ,
372+ $typ( FileAstId <$ast >) ,
413373 ) +
414374 }
415375
416376 impl ModItem {
417- pub fn ast_id( & self , tree : & ItemTree ) -> FileAstId <ast:: Item > {
377+ pub fn ast_id( self ) -> FileAstId <ast:: Item > {
418378 match self {
419- $( ModItem :: $typ( it) => tree [ it . index ( ) ] . ast_id ( ) . upcast( ) ) ,+
379+ $( ModItem :: $typ( it) => it . upcast( ) ) ,+
420380 }
421381 }
422382 }
423383
424384 $(
425- impl From <FileItemTreeId <$typ >> for ModItem {
426- fn from( id: FileItemTreeId <$typ >) -> ModItem {
385+ impl From <FileAstId <$ast >> for ModItem {
386+ fn from( id: FileAstId <$ast >) -> ModItem {
427387 ModItem :: $typ( id)
428388 }
429389 }
@@ -433,20 +393,20 @@ macro_rules! mod_items {
433393 impl ItemTreeNode for $typ {
434394 type Source = $ast;
435395
436- fn ast_id( & self ) -> FileAstId <Self :: Source > {
396+ fn ast_id( & self ) -> FileAstId <$ast > {
437397 self . ast_id
438398 }
439399
440- fn lookup( tree: & ItemTree , index: Idx < Self >) -> & Self {
441- & tree. data( ) . $fld[ index]
400+ fn lookup( tree: & ItemTree , index: FileAstId <$ast >) -> & Self {
401+ & tree. data( ) . $fld[ & index]
442402 }
443403 }
444404
445- impl Index <Idx <$typ >> for ItemTree {
405+ impl Index <FileAstId <$ast >> for ItemTree {
446406 type Output = $typ;
447407
448- fn index( & self , index: Idx <$typ >) -> & Self :: Output {
449- & self . data( ) . $fld[ index]
408+ fn index( & self , index: FileAstId <$ast >) -> & Self :: Output {
409+ & self . data( ) . $fld[ & index]
450410 }
451411 }
452412 ) +
@@ -506,13 +466,6 @@ impl Index<RawVisibilityId> for ItemTree {
506466 }
507467}
508468
509- impl < N : ItemTreeNode > Index < FileItemTreeId < N > > for ItemTree {
510- type Output = N ;
511- fn index ( & self , id : FileItemTreeId < N > ) -> & N {
512- N :: lookup ( self , id. index ( ) )
513- }
514- }
515-
516469#[ derive( Debug , Clone , Eq , PartialEq ) ]
517470pub struct Use {
518471 pub visibility : RawVisibilityId ,
0 commit comments