@@ -63,7 +63,7 @@ impl<'tcx> InferCtxt<'tcx> {
63
63
F : FnOnce ( & CombinedSnapshot < ' tcx > ) -> Result < T , E > ,
64
64
E : NoSnapshotLeaks < ' tcx > ,
65
65
{
66
- let no_leaks_data = E :: mk_data_snapshot_start ( self ) ;
66
+ let no_leaks_data = E :: snapshot_start_data ( self ) ;
67
67
let snapshot = self . start_snapshot ( ) ;
68
68
let r = f ( & snapshot) ;
69
69
debug ! ( "commit_if_ok() -- r.is_ok() = {}" , r. is_ok( ) ) ;
@@ -73,9 +73,9 @@ impl<'tcx> InferCtxt<'tcx> {
73
73
Ok ( value)
74
74
}
75
75
Err ( err) => {
76
- let no_leaks_data = E :: mk_data_snapshot_end ( self , no_leaks_data) ;
76
+ let no_leaks_data = E :: end_of_snapshot ( self , err , no_leaks_data) ;
77
77
self . rollback_to ( snapshot) ;
78
- Err ( E :: avoid_leaks ( err , self , no_leaks_data) )
78
+ Err ( E :: avoid_leaks ( self , no_leaks_data) )
79
79
}
80
80
}
81
81
}
@@ -87,12 +87,12 @@ impl<'tcx> InferCtxt<'tcx> {
87
87
F : FnOnce ( & CombinedSnapshot < ' tcx > ) -> R ,
88
88
R : NoSnapshotLeaks < ' tcx > ,
89
89
{
90
- let no_leaks_data = R :: mk_data_snapshot_start ( self ) ;
90
+ let no_leaks_data = R :: snapshot_start_data ( self ) ;
91
91
let snapshot = self . start_snapshot ( ) ;
92
92
let r = f ( & snapshot) ;
93
- let no_leaks_data = R :: mk_data_snapshot_end ( self , no_leaks_data) ;
93
+ let no_leaks_data = R :: end_of_snapshot ( self , r , no_leaks_data) ;
94
94
self . rollback_to ( snapshot) ;
95
- R :: avoid_leaks ( r , self , no_leaks_data)
95
+ R :: avoid_leaks ( self , no_leaks_data)
96
96
}
97
97
98
98
pub fn probe_unchecked < R , F > ( & self , f : F ) -> R
@@ -139,21 +139,30 @@ pub struct VariableLengths {
139
139
}
140
140
141
141
pub trait NoSnapshotLeaks < ' tcx > {
142
- type DataStart ;
143
- type DataEnd ;
144
- fn mk_data_snapshot_start ( infcx : & InferCtxt < ' tcx > ) -> Self :: DataStart ;
145
- fn mk_data_snapshot_end ( infcx : & InferCtxt < ' tcx > , start : Self :: DataStart ) -> Self :: DataEnd ;
146
- fn avoid_leaks ( self , infcx : & InferCtxt < ' tcx > , data : Self :: DataEnd ) -> Self ;
142
+ type StartData ;
143
+ type EndData ;
144
+ fn snapshot_start_data ( infcx : & InferCtxt < ' tcx > ) -> Self :: StartData ;
145
+ fn end_of_snapshot (
146
+ infcx : & InferCtxt < ' tcx > ,
147
+ this : Self ,
148
+ start : Self :: StartData ,
149
+ ) -> Self :: EndData ;
150
+ fn avoid_leaks ( infcx : & InferCtxt < ' tcx > , data : Self :: EndData ) -> Self ;
147
151
}
148
152
149
153
pub trait TrivialNoSnapshotLeaks < ' tcx > { }
150
154
impl < ' tcx , T : TrivialNoSnapshotLeaks < ' tcx > > NoSnapshotLeaks < ' tcx > for T {
151
- type DataStart = ( ) ;
152
- type DataEnd = ( ) ;
153
- fn mk_data_snapshot_start ( _: & InferCtxt < ' tcx > ) { }
154
- fn mk_data_snapshot_end ( _: & InferCtxt < ' tcx > , _: ( ) ) { }
155
- fn avoid_leaks ( self , _: & InferCtxt < ' tcx > , _: ( ) ) -> Self {
156
- self
155
+ type StartData = ( ) ;
156
+ type EndData = T ;
157
+ #[ inline]
158
+ fn snapshot_start_data ( _: & InferCtxt < ' tcx > ) { }
159
+ #[ inline]
160
+ fn end_of_snapshot ( _: & InferCtxt < ' tcx > , this : Self , _: ( ) ) -> T {
161
+ this
162
+ }
163
+ #[ inline]
164
+ fn avoid_leaks ( _: & InferCtxt < ' tcx > , this : T ) -> Self {
165
+ this
157
166
}
158
167
}
159
168
@@ -200,16 +209,23 @@ mod impls {
200
209
fudge_vars_no_snapshot_leaks ! ( ' tcx, MismatchedProjectionTypes <' tcx>) ;
201
210
202
211
impl < ' tcx , T : NoSnapshotLeaks < ' tcx > > NoSnapshotLeaks < ' tcx > for Option < T > {
203
- type DataStart = T :: DataStart ;
204
- type DataEnd = T :: DataEnd ;
205
- fn mk_data_snapshot_start ( infcx : & InferCtxt < ' tcx > ) -> T :: DataStart {
206
- T :: mk_data_snapshot_start ( infcx)
212
+ type StartData = T :: StartData ;
213
+ type EndData = Option < T :: EndData > ;
214
+ #[ inline]
215
+ fn snapshot_start_data ( infcx : & InferCtxt < ' tcx > ) -> T :: StartData {
216
+ T :: snapshot_start_data ( infcx)
207
217
}
208
- fn mk_data_snapshot_end ( infcx : & InferCtxt < ' tcx > , start_data : T :: DataStart ) -> T :: DataEnd {
209
- T :: mk_data_snapshot_end ( infcx, start_data)
218
+ #[ inline]
219
+ fn end_of_snapshot (
220
+ infcx : & InferCtxt < ' tcx > ,
221
+ this : Option < T > ,
222
+ start_data : T :: StartData ,
223
+ ) -> Option < T :: EndData > {
224
+ this. map ( |this| T :: end_of_snapshot ( infcx, this, start_data) )
210
225
}
211
- fn avoid_leaks ( self , infcx : & InferCtxt < ' tcx > , data : Self :: DataEnd ) -> Self {
212
- self . map ( |value| value. avoid_leaks ( infcx, data) )
226
+ #[ inline]
227
+ fn avoid_leaks ( infcx : & InferCtxt < ' tcx > , data : Self :: EndData ) -> Self {
228
+ data. map ( |data| T :: avoid_leaks ( infcx, data) )
213
229
}
214
230
}
215
231
@@ -218,31 +234,33 @@ mod impls {
218
234
T : NoSnapshotLeaks < ' tcx > ,
219
235
E : NoSnapshotLeaks < ' tcx > ,
220
236
{
221
- type DataStart = ( T :: DataStart , E :: DataStart ) ;
222
- type DataEnd = ( T :: DataEnd , E :: DataEnd ) ;
223
- fn mk_data_snapshot_start ( infcx : & InferCtxt < ' tcx > ) -> Self :: DataStart {
224
- ( T :: mk_data_snapshot_start ( infcx) , E :: mk_data_snapshot_start ( infcx) )
237
+ type StartData = ( T :: StartData , E :: StartData ) ;
238
+ type EndData = Result < T :: EndData , E :: EndData > ;
239
+ #[ inline]
240
+ fn snapshot_start_data ( infcx : & InferCtxt < ' tcx > ) -> Self :: StartData {
241
+ ( T :: snapshot_start_data ( infcx) , E :: snapshot_start_data ( infcx) )
225
242
}
226
- fn mk_data_snapshot_end ( infcx : & InferCtxt < ' tcx > , ( t, e) : Self :: DataStart ) -> Self :: DataEnd {
227
- ( T :: mk_data_snapshot_end ( infcx, t) , E :: mk_data_snapshot_end ( infcx, e) )
243
+ #[ inline]
244
+ fn end_of_snapshot (
245
+ infcx : & InferCtxt < ' tcx > ,
246
+ this : Self ,
247
+ ( t, e) : Self :: StartData ,
248
+ ) -> Self :: EndData {
249
+ match this {
250
+ Ok ( value) => Ok ( T :: end_of_snapshot ( infcx, value, t) ) ,
251
+ Err ( err) => Err ( E :: end_of_snapshot ( infcx, err, e) ) ,
252
+ }
228
253
}
229
- fn avoid_leaks ( self , infcx : & InferCtxt < ' tcx > , ( t, e) : Self :: DataEnd ) -> Self {
230
- match self {
231
- Ok ( value) => Ok ( value. avoid_leaks ( infcx, t) ) ,
232
- Err ( err) => Err ( err. avoid_leaks ( infcx, e) ) ,
254
+
255
+ #[ inline]
256
+ fn avoid_leaks ( infcx : & InferCtxt < ' tcx > , data : Self :: EndData ) -> Self {
257
+ match data {
258
+ Ok ( value) => Ok ( T :: avoid_leaks ( infcx, value) ) ,
259
+ Err ( err) => Err ( E :: avoid_leaks ( infcx, err) ) ,
233
260
}
234
261
}
235
262
}
236
263
237
264
impl < ' tcx , T : TrivialNoSnapshotLeaks < ' tcx > > TrivialNoSnapshotLeaks < ' tcx > for Vec < T > { }
238
-
239
- impl < ' tcx , V > NoSnapshotLeaks < ' tcx > for Canonical < ' tcx , V > {
240
- type DataStart = ( ) ;
241
- type DataEnd = ( ) ;
242
- fn mk_data_snapshot_start ( _: & InferCtxt < ' tcx > ) { }
243
- fn mk_data_snapshot_end ( _: & InferCtxt < ' tcx > , _: ( ) ) { }
244
- fn avoid_leaks ( self , _: & InferCtxt < ' tcx > , _: ( ) ) -> Self {
245
- self
246
- }
247
- }
265
+ impl < ' tcx , V > TrivialNoSnapshotLeaks < ' tcx > for Canonical < ' tcx , V > { }
248
266
}
0 commit comments