@@ -3,23 +3,27 @@ use rustc_middle::bug;
33use rustc_middle:: ty:: { self , OpaqueHiddenType , OpaqueTypeKey , Ty } ;
44use tracing:: instrument;
55
6- use super :: { OpaqueTypeDecl , OpaqueTypeMap } ;
6+ use super :: OpaqueTypeMap ;
77use crate :: infer:: snapshot:: undo_log:: { InferCtxtUndoLogs , UndoLog } ;
88
99#[ derive( Default , Debug , Clone ) ]
1010pub ( crate ) struct OpaqueTypeStorage < ' tcx > {
1111 /// Opaque types found in explicit return types and their
1212 /// associated fresh inference variable. Writeback resolves these
1313 /// variables to get the concrete type, which can be used to
14- /// 'de-opaque' OpaqueTypeDecl , after typeck is done with all functions.
14+ /// 'de-opaque' OpaqueHiddenType , after typeck is done with all functions.
1515 pub opaque_types : OpaqueTypeMap < ' tcx > ,
1616}
1717
1818impl < ' tcx > OpaqueTypeStorage < ' tcx > {
1919 #[ instrument( level = "debug" ) ]
20- pub ( crate ) fn remove ( & mut self , key : OpaqueTypeKey < ' tcx > , idx : Option < OpaqueHiddenType < ' tcx > > ) {
21- if let Some ( idx) = idx {
22- self . opaque_types . get_mut ( & key) . unwrap ( ) . hidden_type = idx;
20+ pub ( crate ) fn remove (
21+ & mut self ,
22+ key : OpaqueTypeKey < ' tcx > ,
23+ prev : Option < OpaqueHiddenType < ' tcx > > ,
24+ ) {
25+ if let Some ( prev) = prev {
26+ * self . opaque_types . get_mut ( & key) . unwrap ( ) = prev;
2327 } else {
2428 // FIXME(#120456) - is `swap_remove` correct?
2529 match self . opaque_types . swap_remove ( & key) {
@@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
5963 key : OpaqueTypeKey < ' tcx > ,
6064 hidden_type : OpaqueHiddenType < ' tcx > ,
6165 ) -> Option < Ty < ' tcx > > {
62- if let Some ( decl ) = self . storage . opaque_types . get_mut ( & key) {
63- let prev = std:: mem:: replace ( & mut decl . hidden_type , hidden_type) ;
66+ if let Some ( entry ) = self . storage . opaque_types . get_mut ( & key) {
67+ let prev = std:: mem:: replace ( entry , hidden_type) ;
6468 self . undo_log . push ( UndoLog :: OpaqueTypes ( key, Some ( prev) ) ) ;
6569 return Some ( prev. ty ) ;
6670 }
67- let decl = OpaqueTypeDecl { hidden_type } ;
68- self . storage . opaque_types . insert ( key, decl) ;
71+ self . storage . opaque_types . insert ( key, hidden_type) ;
6972 self . undo_log . push ( UndoLog :: OpaqueTypes ( key, None ) ) ;
7073 None
7174 }
0 commit comments