@@ -265,7 +265,7 @@ pub enum LateBoundRegionConversionTime {
265
265
///
266
266
/// See `error_reporting.rs` for more details
267
267
#[ derive( Clone , Debug ) ]
268
- pub enum RegionVariableOrigin < ' tcx > {
268
+ pub enum RegionVariableOrigin {
269
269
// Region variables created for ill-categorized reasons,
270
270
// mostly indicates places in need of refactoring
271
271
MiscVariable ( Span ) ,
@@ -280,7 +280,7 @@ pub enum RegionVariableOrigin<'tcx> {
280
280
Autoref ( Span ) ,
281
281
282
282
// Regions created as part of an automatic coercion
283
- Coercion ( TypeTrace < ' tcx > ) ,
283
+ Coercion ( Span ) ,
284
284
285
285
// Region variables created as the values for early-bound regions
286
286
EarlyBoundRegion ( Span , ast:: Name ) ,
@@ -343,8 +343,7 @@ pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
343
343
values : Types ( expected_found ( a_is_expected, a, b) )
344
344
} ;
345
345
346
- let result =
347
- cx. commit_if_ok ( || cx. lub ( a_is_expected, trace. clone ( ) ) . tys ( a, b) ) ;
346
+ let result = cx. commit_if_ok ( |_| cx. lub ( a_is_expected, trace. clone ( ) ) . tys ( a, b) ) ;
348
347
match result {
349
348
Ok ( t) => t,
350
349
Err ( ref err) => {
@@ -362,9 +361,7 @@ pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
362
361
-> UnitResult < ' tcx >
363
362
{
364
363
debug ! ( "mk_subty({} <: {})" , a. repr( cx. tcx) , b. repr( cx. tcx) ) ;
365
- cx. commit_if_ok ( || {
366
- cx. sub_types ( a_is_expected, origin, a, b)
367
- } )
364
+ cx. sub_types ( a_is_expected, origin, a, b)
368
365
}
369
366
370
367
pub fn can_mk_subty < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > ,
@@ -404,8 +401,7 @@ pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
404
401
-> UnitResult < ' tcx >
405
402
{
406
403
debug ! ( "mk_eqty({} <: {})" , a. repr( cx. tcx) , b. repr( cx. tcx) ) ;
407
- cx. commit_if_ok (
408
- || cx. eq_types ( a_is_expected, origin, a, b) )
404
+ cx. commit_if_ok ( |_| cx. eq_types ( a_is_expected, origin, a, b) )
409
405
}
410
406
411
407
pub fn mk_sub_poly_trait_refs < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > ,
@@ -417,8 +413,7 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
417
413
{
418
414
debug ! ( "mk_sub_trait_refs({} <: {})" ,
419
415
a. repr( cx. tcx) , b. repr( cx. tcx) ) ;
420
- cx. commit_if_ok (
421
- || cx. sub_poly_trait_refs ( a_is_expected, origin, a. clone ( ) , b. clone ( ) ) )
416
+ cx. commit_if_ok ( |_| cx. sub_poly_trait_refs ( a_is_expected, origin, a. clone ( ) , b. clone ( ) ) )
422
417
}
423
418
424
419
fn expected_found < T > ( a_is_expected : bool ,
@@ -476,25 +471,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
476
471
}
477
472
}
478
473
479
- pub fn combine_fields < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
480
- -> CombineFields < ' b , ' tcx > {
474
+ fn combine_fields < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
475
+ -> CombineFields < ' b , ' tcx > {
481
476
CombineFields { infcx : self ,
482
477
a_is_expected : a_is_expected,
483
478
trace : trace}
484
479
}
485
480
486
- pub fn equate < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
487
- -> Equate < ' b , ' tcx > {
481
+ fn equate < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
482
+ -> Equate < ' b , ' tcx > {
488
483
Equate ( self . combine_fields ( a_is_expected, trace) )
489
484
}
490
485
491
- pub fn sub < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
492
- -> Sub < ' b , ' tcx > {
486
+ fn sub < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
487
+ -> Sub < ' b , ' tcx > {
493
488
Sub ( self . combine_fields ( a_is_expected, trace) )
494
489
}
495
490
496
- pub fn lub < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
497
- -> Lub < ' b , ' tcx > {
491
+ fn lub < ' b > ( & ' b self , a_is_expected : bool , trace : TypeTrace < ' tcx > )
492
+ -> Lub < ' b , ' tcx > {
498
493
Lub ( self . combine_fields ( a_is_expected, trace) )
499
494
}
500
495
@@ -558,11 +553,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
558
553
r
559
554
}
560
555
561
- /// Execute `f` and commit the bindings if successful
556
+ /// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`
562
557
pub fn commit_if_ok < T , E , F > ( & self , f : F ) -> Result < T , E > where
563
- F : FnOnce ( ) -> Result < T , E >
558
+ F : FnOnce ( & CombinedSnapshot ) -> Result < T , E >
564
559
{
565
- self . commit_unconditionally ( move || self . try ( move |_| f ( ) ) )
560
+ debug ! ( "commit_if_ok()" ) ;
561
+ let snapshot = self . start_snapshot ( ) ;
562
+ let r = f ( & snapshot) ;
563
+ debug ! ( "commit_if_ok() -- r.is_ok() = {}" , r. is_ok( ) ) ;
564
+ match r {
565
+ Ok ( _) => { self . commit_from ( snapshot) ; }
566
+ Err ( _) => { self . rollback_to ( snapshot) ; }
567
+ }
568
+ r
566
569
}
567
570
568
571
/// Execute `f` and commit only the region bindings if successful.
@@ -577,7 +580,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
577
580
float_snapshot,
578
581
region_vars_snapshot } = self . start_snapshot ( ) ;
579
582
580
- let r = self . try ( move |_| f ( ) ) ;
583
+ let r = self . commit_if_ok ( |_| f ( ) ) ;
581
584
582
585
// Roll back any non-region bindings - they should be resolved
583
586
// inside `f`, with, e.g. `resolve_type_vars_if_possible`.
@@ -598,25 +601,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
598
601
r
599
602
}
600
603
601
- /// Execute `f`, unroll bindings on panic
602
- pub fn try < T , E , F > ( & self , f : F ) -> Result < T , E > where
603
- F : FnOnce ( & CombinedSnapshot ) -> Result < T , E >
604
- {
605
- debug ! ( "try()" ) ;
606
- let snapshot = self . start_snapshot ( ) ;
607
- let r = f ( & snapshot) ;
608
- debug ! ( "try() -- r.is_ok() = {}" , r. is_ok( ) ) ;
609
- match r {
610
- Ok ( _) => {
611
- self . commit_from ( snapshot) ;
612
- }
613
- Err ( _) => {
614
- self . rollback_to ( snapshot) ;
615
- }
616
- }
617
- r
618
- }
619
-
620
604
/// Execute `f` then unroll any bindings it creates
621
605
pub fn probe < R , F > ( & self , f : F ) -> R where
622
606
F : FnOnce ( & CombinedSnapshot ) -> R ,
@@ -643,7 +627,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
643
627
-> UnitResult < ' tcx >
644
628
{
645
629
debug ! ( "sub_types({} <: {})" , a. repr( self . tcx) , b. repr( self . tcx) ) ;
646
- self . commit_if_ok ( || {
630
+ self . commit_if_ok ( |_ | {
647
631
let trace = TypeTrace :: types ( origin, a_is_expected, a, b) ;
648
632
self . sub ( a_is_expected, trace) . tys ( a, b) . map ( |_| ( ) )
649
633
} )
@@ -656,7 +640,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
656
640
b : Ty < ' tcx > )
657
641
-> UnitResult < ' tcx >
658
642
{
659
- self . commit_if_ok ( || {
643
+ self . commit_if_ok ( |_ | {
660
644
let trace = TypeTrace :: types ( origin, a_is_expected, a, b) ;
661
645
self . equate ( a_is_expected, trace) . tys ( a, b) . map ( |_| ( ) )
662
646
} )
@@ -672,7 +656,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
672
656
debug ! ( "sub_trait_refs({} <: {})" ,
673
657
a. repr( self . tcx) ,
674
658
b. repr( self . tcx) ) ;
675
- self . commit_if_ok ( || {
659
+ self . commit_if_ok ( |_ | {
676
660
let trace = TypeTrace {
677
661
origin : origin,
678
662
values : TraitRefs ( expected_found ( a_is_expected, a. clone ( ) , b. clone ( ) ) )
@@ -691,7 +675,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
691
675
debug ! ( "sub_poly_trait_refs({} <: {})" ,
692
676
a. repr( self . tcx) ,
693
677
b. repr( self . tcx) ) ;
694
- self . commit_if_ok ( || {
678
+ self . commit_if_ok ( |_ | {
695
679
let trace = TypeTrace {
696
680
origin : origin,
697
681
values : PolyTraitRefs ( expected_found ( a_is_expected, a. clone ( ) , b. clone ( ) ) )
@@ -749,7 +733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
749
733
span : Span ,
750
734
predicate : & ty:: PolyEquatePredicate < ' tcx > )
751
735
-> UnitResult < ' tcx > {
752
- self . try ( |snapshot| {
736
+ self . commit_if_ok ( |snapshot| {
753
737
let ( ty:: EquatePredicate ( a, b) , skol_map) =
754
738
self . skolemize_late_bound_regions ( predicate, snapshot) ;
755
739
let origin = EquatePredicate ( span) ;
@@ -762,7 +746,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
762
746
span : Span ,
763
747
predicate : & ty:: PolyRegionOutlivesPredicate )
764
748
-> UnitResult < ' tcx > {
765
- self . try ( |snapshot| {
749
+ self . commit_if_ok ( |snapshot| {
766
750
let ( ty:: OutlivesPredicate ( r_a, r_b) , skol_map) =
767
751
self . skolemize_late_bound_regions ( predicate, snapshot) ;
768
752
let origin = RelateRegionParamBound ( span) ;
@@ -801,7 +785,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
801
785
. new_key ( None )
802
786
}
803
787
804
- pub fn next_region_var ( & self , origin : RegionVariableOrigin < ' tcx > ) -> ty:: Region {
788
+ pub fn next_region_var ( & self , origin : RegionVariableOrigin ) -> ty:: Region {
805
789
ty:: ReInfer ( ty:: ReVar ( self . region_vars . new_region_var ( origin) ) )
806
790
}
807
791
@@ -1253,14 +1237,14 @@ impl<'tcx> Repr<'tcx> for SubregionOrigin<'tcx> {
1253
1237
}
1254
1238
}
1255
1239
1256
- impl < ' tcx > RegionVariableOrigin < ' tcx > {
1240
+ impl RegionVariableOrigin {
1257
1241
pub fn span ( & self ) -> Span {
1258
1242
match * self {
1259
1243
MiscVariable ( a) => a,
1260
1244
PatternRegion ( a) => a,
1261
1245
AddrOfRegion ( a) => a,
1262
1246
Autoref ( a) => a,
1263
- Coercion ( ref a) => a. span ( ) ,
1247
+ Coercion ( a) => a,
1264
1248
EarlyBoundRegion ( a, _) => a,
1265
1249
LateBoundRegion ( a, _, _) => a,
1266
1250
BoundRegionInCoherence ( _) => codemap:: DUMMY_SP ,
@@ -1269,7 +1253,7 @@ impl<'tcx> RegionVariableOrigin<'tcx> {
1269
1253
}
1270
1254
}
1271
1255
1272
- impl < ' tcx > Repr < ' tcx > for RegionVariableOrigin < ' tcx > {
1256
+ impl < ' tcx > Repr < ' tcx > for RegionVariableOrigin {
1273
1257
fn repr ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
1274
1258
match * self {
1275
1259
MiscVariable ( a) => {
@@ -1282,7 +1266,7 @@ impl<'tcx> Repr<'tcx> for RegionVariableOrigin<'tcx> {
1282
1266
format ! ( "AddrOfRegion({})" , a. repr( tcx) )
1283
1267
}
1284
1268
Autoref ( a) => format ! ( "Autoref({})" , a. repr( tcx) ) ,
1285
- Coercion ( ref a) => format ! ( "Coercion({})" , a. repr( tcx) ) ,
1269
+ Coercion ( a) => format ! ( "Coercion({})" , a. repr( tcx) ) ,
1286
1270
EarlyBoundRegion ( a, b) => {
1287
1271
format ! ( "EarlyBoundRegion({},{})" , a. repr( tcx) , b. repr( tcx) )
1288
1272
}
0 commit comments