@@ -62,11 +62,7 @@ use std::{
62
62
panic:: { RefUnwindSafe , UnwindSafe } ,
63
63
} ;
64
64
65
- use base_db:: {
66
- impl_intern_key,
67
- salsa:: { self , InternId } ,
68
- CrateId , ProcMacroKind ,
69
- } ;
65
+ use base_db:: { impl_intern_key, salsa, CrateId , ProcMacroKind } ;
70
66
use hir_expand:: {
71
67
ast_id_map:: FileAstId ,
72
68
attrs:: { Attr , AttrId , AttrInput } ,
@@ -482,8 +478,16 @@ impl_from!(
482
478
/// Id of the anonymous const block expression and patterns. This is very similar to `ClosureId` and
483
479
/// shouldn't be a `DefWithBodyId` since its type inference is dependent on its parent.
484
480
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
485
- pub struct ConstBlockId ( InternId ) ;
486
- impl_intern_key ! ( ConstBlockId ) ;
481
+ pub struct ConstBlockId ( salsa:: InternId ) ;
482
+ impl_intern ! ( ConstBlockId , ConstBlockLoc , intern_anonymous_const, lookup_intern_anonymous_const) ;
483
+
484
+ #[ derive( Debug , Hash , PartialEq , Eq , Clone ) ]
485
+ pub struct ConstBlockLoc {
486
+ /// The parent of the anonymous const block.
487
+ pub parent : DefWithBodyId ,
488
+ /// The root expression of this const block in the parent body.
489
+ pub root : hir:: ExprId ,
490
+ }
487
491
488
492
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
489
493
pub enum TypeOwnerId {
@@ -563,6 +567,7 @@ impl From<GenericDefId> for TypeOwnerId {
563
567
}
564
568
}
565
569
570
+ // FIXME: This should not be a thing
566
571
/// A thing that we want to store in interned ids, but we don't know its type in `hir-def`. This is
567
572
/// currently only used in `InTypeConstId` for storing the type (which has type `Ty` defined in
568
573
/// the `hir-ty` crate) of the constant in its id, which is a temporary hack so we may want
@@ -620,13 +625,26 @@ impl Clone for Box<dyn OpaqueInternableThing> {
620
625
/// length (like `[u8; 2 + 2]`). These constants are body owner and are a variant of `DefWithBodyId`. These
621
626
/// are not called `AnonymousConstId` to prevent confusion with [`ConstBlockId`].
622
627
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
623
- pub struct InTypeConstId ( InternId ) ;
624
- type InTypeConstLoc = ( AstId < ast:: ConstArg > , TypeOwnerId , Box < dyn OpaqueInternableThing > ) ;
628
+ pub struct InTypeConstId ( salsa:: InternId ) ;
625
629
impl_intern ! ( InTypeConstId , InTypeConstLoc , intern_in_type_const, lookup_intern_in_type_const) ;
626
630
631
+ #[ derive( Debug , Hash , Eq , Clone ) ]
632
+ pub struct InTypeConstLoc {
633
+ pub id : AstId < ast:: ConstArg > ,
634
+ /// The thing this const arg appears in
635
+ pub owner : TypeOwnerId ,
636
+ pub thing : Box < dyn OpaqueInternableThing > ,
637
+ }
638
+
639
+ impl PartialEq for InTypeConstLoc {
640
+ fn eq ( & self , other : & Self ) -> bool {
641
+ self . id == other. id && self . owner == other. owner && & * self . thing == & * other. thing
642
+ }
643
+ }
644
+
627
645
impl InTypeConstId {
628
646
pub fn source ( & self , db : & dyn db:: DefDatabase ) -> ast:: ConstArg {
629
- let src = self . lookup ( db) . 0 ;
647
+ let src = self . lookup ( db) . id ;
630
648
let file_id = src. file_id ;
631
649
let root = & db. parse_or_expand ( file_id) ;
632
650
db. ast_id_map ( file_id) . get ( src. value ) . to_node ( root)
@@ -647,15 +665,9 @@ impl_from!(ConstId, ConstBlockId, InTypeConstId for GeneralConstId);
647
665
impl GeneralConstId {
648
666
pub fn generic_def ( self , db : & dyn db:: DefDatabase ) -> Option < GenericDefId > {
649
667
match self {
650
- GeneralConstId :: ConstId ( x) => Some ( x. into ( ) ) ,
651
- GeneralConstId :: ConstBlockId ( x) => {
652
- let ( parent, _) = db. lookup_intern_anonymous_const ( x) ;
653
- parent. as_generic_def_id ( )
654
- }
655
- GeneralConstId :: InTypeConstId ( x) => {
656
- let ( _, parent, _) = x. lookup ( db) ;
657
- parent. as_generic_def_id ( )
658
- }
668
+ GeneralConstId :: ConstId ( it) => Some ( it. into ( ) ) ,
669
+ GeneralConstId :: ConstBlockId ( it) => it. lookup ( db) . parent . as_generic_def_id ( ) ,
670
+ GeneralConstId :: InTypeConstId ( it) => it. lookup ( db) . owner . as_generic_def_id ( ) ,
659
671
}
660
672
}
661
673
@@ -902,7 +914,7 @@ impl HasModule for TypeOwnerId {
902
914
TypeOwnerId :: FunctionId ( x) => x. lookup ( db) . module ( db) ,
903
915
TypeOwnerId :: StaticId ( x) => x. lookup ( db) . module ( db) ,
904
916
TypeOwnerId :: ConstId ( x) => x. lookup ( db) . module ( db) ,
905
- TypeOwnerId :: InTypeConstId ( x) => x. lookup ( db) . 1 . module ( db) ,
917
+ TypeOwnerId :: InTypeConstId ( x) => x. lookup ( db) . owner . module ( db) ,
906
918
TypeOwnerId :: AdtId ( x) => x. module ( db) ,
907
919
TypeOwnerId :: TraitId ( x) => x. lookup ( db) . container ,
908
920
TypeOwnerId :: TraitAliasId ( x) => x. lookup ( db) . container ,
@@ -921,7 +933,7 @@ impl HasModule for DefWithBodyId {
921
933
DefWithBodyId :: StaticId ( it) => it. lookup ( db) . module ( db) ,
922
934
DefWithBodyId :: ConstId ( it) => it. lookup ( db) . module ( db) ,
923
935
DefWithBodyId :: VariantId ( it) => it. parent . lookup ( db) . container ,
924
- DefWithBodyId :: InTypeConstId ( it) => it. lookup ( db) . 1 . module ( db) ,
936
+ DefWithBodyId :: InTypeConstId ( it) => it. lookup ( db) . owner . module ( db) ,
925
937
}
926
938
}
927
939
}
0 commit comments