@@ -62,11 +62,7 @@ use std::{
6262 panic:: { RefUnwindSafe , UnwindSafe } ,
6363} ;
6464
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 } ;
7066use hir_expand:: {
7167 ast_id_map:: FileAstId ,
7268 attrs:: { Attr , AttrId , AttrInput } ,
@@ -482,8 +478,16 @@ impl_from!(
482478/// Id of the anonymous const block expression and patterns. This is very similar to `ClosureId` and
483479/// shouldn't be a `DefWithBodyId` since its type inference is dependent on its parent.
484480#[ 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+ }
487491
488492#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
489493pub enum TypeOwnerId {
@@ -563,6 +567,7 @@ impl From<GenericDefId> for TypeOwnerId {
563567 }
564568}
565569
570+ // FIXME: This should not be a thing
566571/// A thing that we want to store in interned ids, but we don't know its type in `hir-def`. This is
567572/// currently only used in `InTypeConstId` for storing the type (which has type `Ty` defined in
568573/// 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> {
620625/// length (like `[u8; 2 + 2]`). These constants are body owner and are a variant of `DefWithBodyId`. These
621626/// are not called `AnonymousConstId` to prevent confusion with [`ConstBlockId`].
622627#[ 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 ) ;
625629impl_intern ! ( InTypeConstId , InTypeConstLoc , intern_in_type_const, lookup_intern_in_type_const) ;
626630
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+
627645impl InTypeConstId {
628646 pub fn source ( & self , db : & dyn db:: DefDatabase ) -> ast:: ConstArg {
629- let src = self . lookup ( db) . 0 ;
647+ let src = self . lookup ( db) . id ;
630648 let file_id = src. file_id ;
631649 let root = & db. parse_or_expand ( file_id) ;
632650 db. ast_id_map ( file_id) . get ( src. value ) . to_node ( root)
@@ -647,15 +665,9 @@ impl_from!(ConstId, ConstBlockId, InTypeConstId for GeneralConstId);
647665impl GeneralConstId {
648666 pub fn generic_def ( self , db : & dyn db:: DefDatabase ) -> Option < GenericDefId > {
649667 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 ( ) ,
659671 }
660672 }
661673
@@ -902,7 +914,7 @@ impl HasModule for TypeOwnerId {
902914 TypeOwnerId :: FunctionId ( x) => x. lookup ( db) . module ( db) ,
903915 TypeOwnerId :: StaticId ( x) => x. lookup ( db) . module ( db) ,
904916 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) ,
906918 TypeOwnerId :: AdtId ( x) => x. module ( db) ,
907919 TypeOwnerId :: TraitId ( x) => x. lookup ( db) . container ,
908920 TypeOwnerId :: TraitAliasId ( x) => x. lookup ( db) . container ,
@@ -921,7 +933,7 @@ impl HasModule for DefWithBodyId {
921933 DefWithBodyId :: StaticId ( it) => it. lookup ( db) . module ( db) ,
922934 DefWithBodyId :: ConstId ( it) => it. lookup ( db) . module ( db) ,
923935 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) ,
925937 }
926938 }
927939}
0 commit comments