@@ -57,7 +57,10 @@ mod test_db;
5757mod macro_expansion_tests;
5858mod pretty;
5959
60- use std:: hash:: { Hash , Hasher } ;
60+ use std:: {
61+ hash:: { Hash , Hasher } ,
62+ panic:: { RefUnwindSafe , UnwindSafe } ,
63+ } ;
6164
6265use base_db:: {
6366 impl_intern_key,
@@ -501,9 +504,40 @@ impl TypeOwnerId {
501504
502505impl_from ! ( ModuleId , DefWithBodyId ( FunctionId , ConstId , StaticId ) , GenericDefId ( AdtId , TypeAliasId , ImplId ) for TypeOwnerId ) ;
503506
507+ /// A thing that we want to store in interned ids, but we don't know its type in `hir-def`
508+ pub trait OpaqueInternableThing :
509+ std:: any:: Any + std:: fmt:: Debug + Sync + Send + UnwindSafe + RefUnwindSafe
510+ {
511+ fn as_any ( & self ) -> & dyn std:: any:: Any ;
512+ fn box_any ( & self ) -> Box < dyn std:: any:: Any > ;
513+ fn dyn_hash ( & self , state : & mut dyn Hasher ) ;
514+ fn dyn_eq ( & self , other : & dyn OpaqueInternableThing ) -> bool ;
515+ fn dyn_clone ( & self ) -> Box < dyn OpaqueInternableThing > ;
516+ }
517+
518+ impl Hash for dyn OpaqueInternableThing {
519+ fn hash < H : Hasher > ( & self , state : & mut H ) {
520+ self . dyn_hash ( state) ;
521+ }
522+ }
523+
524+ impl PartialEq for dyn OpaqueInternableThing {
525+ fn eq ( & self , other : & Self ) -> bool {
526+ self . dyn_eq ( other)
527+ }
528+ }
529+
530+ impl Eq for dyn OpaqueInternableThing { }
531+
532+ impl Clone for Box < dyn OpaqueInternableThing > {
533+ fn clone ( & self ) -> Self {
534+ self . dyn_clone ( )
535+ }
536+ }
537+
504538#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
505539pub struct InTypeConstId ( InternId ) ;
506- type InTypeConstLoc = ( AstId < ast:: Expr > , TypeOwnerId ) ;
540+ type InTypeConstLoc = ( AstId < ast:: Expr > , TypeOwnerId , Box < dyn OpaqueInternableThing > ) ;
507541impl_intern ! ( InTypeConstId , InTypeConstLoc , intern_in_type_const, lookup_intern_in_type_const) ;
508542
509543impl InTypeConstId {
@@ -535,7 +569,7 @@ impl GeneralConstId {
535569 parent. as_generic_def_id ( )
536570 }
537571 GeneralConstId :: InTypeConstId ( x) => {
538- let ( _, parent) = x. lookup ( db) ;
572+ let ( _, parent, _ ) = x. lookup ( db) ;
539573 parent. as_generic_def_id ( )
540574 }
541575 }
0 commit comments