@@ -10,9 +10,8 @@ use rustc_hir::{
1010 def_id:: DefId ,
1111} ;
1212use rustc_middle:: ty:: {
13- self ,
14- subst:: { InternalSubsts , SubstsRef } ,
15- AliasKind , ParamEnv , Ty , TyCtxt , TyKind , TypeFoldable , TypeSuperVisitable , TypeVisitor ,
13+ self , subst:: SubstsRef , AliasKind , ParamEnv , Ty , TyCtxt , TyKind , TypeFoldable ,
14+ TypeSuperVisitable , TypeVisitor ,
1615} ;
1716use rustc_span:: { Symbol , DUMMY_SP } ;
1817use rustc_target:: abi:: FieldIdx ;
@@ -108,8 +107,8 @@ pub struct CloneMap<'tcx> {
108107 // - Body: Will directly use the full body of dependencies, except for program functions
109108 clone_level : CloneLevel ,
110109
111- // DefId of the item which is cloning. Used for trait resolution
112- self_id : CloneNode < ' tcx > , // TODO should this be a TransId?
110+ // TransId of the item which is cloning. Used for trait resolution
111+ self_id : TransId ,
113112 // TODO: Push the graph into an opaque type with tight api boundary
114113 // Graph which is used to calculate the full clone set
115114 clone_graph : DiGraphMap < DepNode < ' tcx > , IndexSet < ( Kind , SymbolKind ) > > ,
@@ -213,23 +212,8 @@ impl<'tcx> CloneMap<'tcx> {
213212 pub ( crate ) fn new ( tcx : TyCtxt < ' tcx > , self_id : TransId , clone_level : CloneLevel ) -> Self {
214213 let mut names = IndexMap :: new ( ) ;
215214
216- let self_id = match self_id {
217- TransId :: Item ( self_id) => {
218- let subst = match tcx. def_kind ( self_id) {
219- DefKind :: Closure => match tcx. type_of ( self_id) . subst_identity ( ) . kind ( ) {
220- TyKind :: Closure ( _, subst) => subst,
221- _ => unreachable ! ( ) ,
222- } ,
223- _ => InternalSubsts :: identity_for_item ( tcx, self_id) ,
224- } ;
225-
226- CloneNode :: new ( tcx, ( self_id, subst) ) . erase_regions ( tcx)
227- }
228- TransId :: TyInv ( inv_kind) => CloneNode :: TyInv ( inv_kind. to_skeleton_ty ( tcx) ) ,
229- } ;
230-
231215 debug ! ( "cloning self: {:?}" , self_id) ;
232- names. insert ( self_id, CloneInfo :: hidden ( ) ) ;
216+ names. insert ( CloneNode :: from_trans_id ( tcx , self_id) , CloneInfo :: hidden ( ) ) ;
233217
234218 CloneMap {
235219 tcx,
@@ -374,8 +358,15 @@ impl<'tcx> CloneMap<'tcx> {
374358 self . value ( def_id, subst)
375359 }
376360
361+ fn self_key ( & self ) -> CloneNode < ' tcx > {
362+ CloneNode :: from_trans_id ( self . tcx , self . self_id )
363+ }
364+
377365 fn self_did ( & self ) -> Option < DefId > {
378- self . self_id . did ( ) . map ( |( self_did, _) | self_did)
366+ match self . self_id {
367+ TransId :: Item ( did) | TransId :: TyInv ( TyInvKind :: Adt ( did) ) => Some ( did) ,
368+ _ => None ,
369+ }
379370 }
380371
381372 fn param_env ( & self , ctx : & TranslationCtx < ' tcx > ) -> ParamEnv < ' tcx > {
@@ -412,8 +403,9 @@ impl<'tcx> CloneMap<'tcx> {
412403 i += 1 ;
413404 trace ! ( "update graph with {:?} (public={:?})" , key, self . names[ & key] . public) ;
414405
415- if key != self . self_id {
416- self . add_graph_edge ( self . self_id , key) ;
406+ let self_key = self . self_key ( ) ;
407+ if key != self_key {
408+ self . add_graph_edge ( self_key, key) ;
417409 }
418410
419411 if self . names [ & key] . kind == Kind :: Hidden {
@@ -448,7 +440,7 @@ impl<'tcx> CloneMap<'tcx> {
448440 }
449441
450442 let inv_kind = TyInvKind :: from_ty ( ty) ;
451- if self . self_id . ty_inv_kind ( ) . is_some_and ( |self_kind| self_kind == inv_kind) {
443+ if let TransId :: TyInv ( self_kind ) = self . self_id && self_kind == inv_kind {
452444 return ;
453445 }
454446
@@ -674,7 +666,7 @@ impl<'tcx> CloneMap<'tcx> {
674666 // Broken because of closures which share a defid for the type *and* function
675667 // debug_assert!(!is_cyclic_directed(&self.clone_graph), "clone graph for {:?} is cyclic", self.self_id );
676668
677- let mut topo = DfsPostOrder :: new ( & self . clone_graph , self . self_id ) ;
669+ let mut topo = DfsPostOrder :: new ( & self . clone_graph , self . self_key ( ) ) ;
678670 while let Some ( node) = topo. walk_next ( & self . clone_graph ) {
679671 trace ! ( "processing node {:?}" , self . names[ & node] . kind) ;
680672
0 commit comments