@@ -37,8 +37,8 @@ mod tests;
37
37
38
38
use std:: {
39
39
fmt:: { self , Debug } ,
40
- hash:: { Hash , Hasher } ,
41
- ops:: { Index , Range } ,
40
+ hash:: Hash ,
41
+ ops:: Index ,
42
42
sync:: OnceLock ,
43
43
} ;
44
44
@@ -51,7 +51,7 @@ use hir_expand::{
51
51
name:: Name ,
52
52
} ;
53
53
use intern:: Interned ;
54
- use la_arena:: { Arena , Idx , RawIdx } ;
54
+ use la_arena:: { Arena , Idx } ;
55
55
use rustc_hash:: FxHashMap ;
56
56
use smallvec:: SmallVec ;
57
57
use span:: { AstIdNode , Edition , FileAstId , SyntaxContext } ;
@@ -277,23 +277,23 @@ struct ItemVisibilities {
277
277
278
278
#[ derive( Default , Debug , Eq , PartialEq ) ]
279
279
struct 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 > ,
297
297
298
298
vis : ItemVisibilities ,
299
299
}
@@ -329,51 +329,11 @@ pub trait ItemTreeNode: Clone {
329
329
fn ast_id ( & self ) -> FileAstId < Self :: Source > ;
330
330
331
331
/// 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 ;
333
333
}
334
334
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 > ;
377
337
378
338
/// Identifies a particular [`ItemTree`].
379
339
#[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash ) ]
@@ -409,21 +369,21 @@ macro_rules! mod_items {
409
369
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
410
370
pub enum ModItem {
411
371
$(
412
- $typ( FileItemTreeId <$typ >) ,
372
+ $typ( FileAstId <$ast >) ,
413
373
) +
414
374
}
415
375
416
376
impl ModItem {
417
- pub fn ast_id( & self , tree : & ItemTree ) -> FileAstId <ast:: Item > {
377
+ pub fn ast_id( self ) -> FileAstId <ast:: Item > {
418
378
match self {
419
- $( ModItem :: $typ( it) => tree [ it . index ( ) ] . ast_id ( ) . upcast( ) ) ,+
379
+ $( ModItem :: $typ( it) => it . upcast( ) ) ,+
420
380
}
421
381
}
422
382
}
423
383
424
384
$(
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 {
427
387
ModItem :: $typ( id)
428
388
}
429
389
}
@@ -433,20 +393,20 @@ macro_rules! mod_items {
433
393
impl ItemTreeNode for $typ {
434
394
type Source = $ast;
435
395
436
- fn ast_id( & self ) -> FileAstId <Self :: Source > {
396
+ fn ast_id( & self ) -> FileAstId <$ast > {
437
397
self . ast_id
438
398
}
439
399
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]
442
402
}
443
403
}
444
404
445
- impl Index <Idx <$typ >> for ItemTree {
405
+ impl Index <FileAstId <$ast >> for ItemTree {
446
406
type Output = $typ;
447
407
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]
450
410
}
451
411
}
452
412
) +
@@ -506,13 +466,6 @@ impl Index<RawVisibilityId> for ItemTree {
506
466
}
507
467
}
508
468
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
-
516
469
#[ derive( Debug , Clone , Eq , PartialEq ) ]
517
470
pub struct Use {
518
471
pub visibility : RawVisibilityId ,
0 commit comments