@@ -3,23 +3,27 @@ use rustc_middle::bug;
3
3
use rustc_middle:: ty:: { self , OpaqueHiddenType , OpaqueTypeKey , Ty } ;
4
4
use tracing:: instrument;
5
5
6
- use super :: { OpaqueTypeDecl , OpaqueTypeMap } ;
6
+ use super :: OpaqueTypeMap ;
7
7
use crate :: infer:: snapshot:: undo_log:: { InferCtxtUndoLogs , UndoLog } ;
8
8
9
9
#[ derive( Default , Debug , Clone ) ]
10
10
pub ( crate ) struct OpaqueTypeStorage < ' tcx > {
11
11
/// Opaque types found in explicit return types and their
12
12
/// associated fresh inference variable. Writeback resolves these
13
13
/// 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.
15
15
pub opaque_types : OpaqueTypeMap < ' tcx > ,
16
16
}
17
17
18
18
impl < ' tcx > OpaqueTypeStorage < ' tcx > {
19
19
#[ 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;
23
27
} else {
24
28
// FIXME(#120456) - is `swap_remove` correct?
25
29
match self . opaque_types . swap_remove ( & key) {
@@ -59,13 +63,12 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
59
63
key : OpaqueTypeKey < ' tcx > ,
60
64
hidden_type : OpaqueHiddenType < ' tcx > ,
61
65
) -> 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) ;
64
68
self . undo_log . push ( UndoLog :: OpaqueTypes ( key, Some ( prev) ) ) ;
65
69
return Some ( prev. ty ) ;
66
70
}
67
- let decl = OpaqueTypeDecl { hidden_type } ;
68
- self . storage . opaque_types . insert ( key, decl) ;
71
+ self . storage . opaque_types . insert ( key, hidden_type) ;
69
72
self . undo_log . push ( UndoLog :: OpaqueTypes ( key, None ) ) ;
70
73
None
71
74
}
0 commit comments