@@ -67,7 +67,7 @@ use rustc::hir::def_id::DefId;
67
67
use rustc:: infer:: { Coercion , InferResult , InferOk } ;
68
68
use rustc:: infer:: type_variable:: TypeVariableOrigin ;
69
69
use rustc:: traits:: { self , ObligationCause , ObligationCauseCode } ;
70
- use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow , AutoBorrowMutability } ;
70
+ use rustc:: ty:: adjustment:: { Adjustment , Adjust , AllowTwoPhase , AutoBorrow , AutoBorrowMutability } ;
71
71
use rustc:: ty:: { self , TypeAndMut , Ty , ClosureSubsts } ;
72
72
use rustc:: ty:: fold:: TypeFoldable ;
73
73
use rustc:: ty:: error:: TypeError ;
@@ -89,7 +89,8 @@ struct Coerce<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
89
89
/// allow deref coercions to create two-phase borrows, at least initially,
90
90
/// but we do need two-phase borrows for function argument reborrows.
91
91
/// See #47489 and #48598
92
- allow_two_phase : bool ,
92
+ /// See docs on the "AllowTwoPhase" type for a more detailed discussion
93
+ allow_two_phase : AllowTwoPhase ,
93
94
}
94
95
95
96
impl < ' a , ' gcx , ' tcx > Deref for Coerce < ' a , ' gcx , ' tcx > {
@@ -131,7 +132,7 @@ fn success<'tcx>(adj: Vec<Adjustment<'tcx>>,
131
132
impl < ' f , ' gcx , ' tcx > Coerce < ' f , ' gcx , ' tcx > {
132
133
fn new ( fcx : & ' f FnCtxt < ' f , ' gcx , ' tcx > ,
133
134
cause : ObligationCause < ' tcx > ,
134
- allow_two_phase : bool ) -> Self {
135
+ allow_two_phase : AllowTwoPhase ) -> Self {
135
136
Coerce {
136
137
fcx,
137
138
cause,
@@ -433,7 +434,10 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
433
434
let mutbl = match mt_b. mutbl {
434
435
hir:: MutImmutable => AutoBorrowMutability :: Immutable ,
435
436
hir:: MutMutable => AutoBorrowMutability :: Mutable {
436
- allow_two_phase_borrow : self . allow_two_phase ,
437
+ allow_two_phase_borrow : match self . allow_two_phase {
438
+ AllowTwoPhase :: Yes => true ,
439
+ AllowTwoPhase :: No => false
440
+ } ,
437
441
}
438
442
} ;
439
443
adjustments. push ( Adjustment {
@@ -761,7 +765,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
761
765
expr : & hir:: Expr ,
762
766
expr_ty : Ty < ' tcx > ,
763
767
target : Ty < ' tcx > ,
764
- allow_two_phase : bool )
768
+ allow_two_phase : AllowTwoPhase )
765
769
-> RelateResult < ' tcx , Ty < ' tcx > > {
766
770
let source = self . resolve_type_vars_with_obligations ( expr_ty) ;
767
771
debug ! ( "coercion::try({:?}: {:?} -> {:?})" , expr, source, target) ;
@@ -782,7 +786,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
782
786
783
787
let cause = self . cause ( syntax_pos:: DUMMY_SP , ObligationCauseCode :: ExprAssignable ) ;
784
788
// We don't ever need two-phase here since we throw out the result of the coercion
785
- let coerce = Coerce :: new ( self , cause, false ) ;
789
+ let coerce = Coerce :: new ( self , cause, AllowTwoPhase :: No ) ;
786
790
self . probe ( |_| coerce. coerce ( source, target) ) . is_ok ( )
787
791
}
788
792
@@ -856,7 +860,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
856
860
// probably aren't processing function arguments here and even if we were,
857
861
// they're going to get autorefed again anyway and we can apply 2-phase borrows
858
862
// at that time.
859
- let mut coerce = Coerce :: new ( self , cause. clone ( ) , false ) ;
863
+ let mut coerce = Coerce :: new ( self , cause. clone ( ) , AllowTwoPhase :: No ) ;
860
864
coerce. use_lub = true ;
861
865
862
866
// First try to coerce the new expression to the type of the previous ones,
@@ -1123,7 +1127,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1123
1127
// Special-case the first expression we are coercing.
1124
1128
// To be honest, I'm not entirely sure why we do this.
1125
1129
// We don't allow two-phase borrows, see comment in try_find_coercion_lub for why
1126
- fcx. try_coerce ( expression, expression_ty, self . expected_ty , false )
1130
+ fcx. try_coerce ( expression, expression_ty, self . expected_ty , AllowTwoPhase :: No )
1127
1131
} else {
1128
1132
match self . expressions {
1129
1133
Expressions :: Dynamic ( ref exprs) =>
0 commit comments