Skip to content

Commit d64bd2a

Browse files
Push AllowTwoPhase down to the HAIR level
For consistency, use AllowTwoPhase everywhere between the frontend and MIR.
1 parent 96ae0ee commit d64bd2a

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

src/librustc/ich/impls_ty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ for ty::adjustment::Adjust<'gcx> {
188188
impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
189189
impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
190190
impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
191+
impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase {
192+
Yes,
193+
No
194+
});
191195

192196
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
193197
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/ty/adjustment.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,15 @@ impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> {
131131
/// new code via two-phase borrows, so we try to limit where we create two-phase
132132
/// capable mutable borrows.
133133
/// See #49434 for tracking.
134+
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
134135
pub enum AllowTwoPhase {
135136
Yes,
136137
No
137138
}
138139

139140
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
140141
pub enum AutoBorrowMutability {
141-
Mutable { allow_two_phase_borrow: bool },
142+
Mutable { allow_two_phase_borrow: AllowTwoPhase },
142143
Immutable,
143144
}
144145

src/librustc_mir/hair/cx/expr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,13 @@ trait ToBorrowKind { fn to_borrow_kind(&self) -> BorrowKind; }
662662

663663
impl ToBorrowKind for AutoBorrowMutability {
664664
fn to_borrow_kind(&self) -> BorrowKind {
665+
use rustc::ty::adjustment::AllowTwoPhase;
665666
match *self {
666667
AutoBorrowMutability::Mutable { allow_two_phase_borrow } =>
667-
BorrowKind::Mut { allow_two_phase_borrow },
668+
BorrowKind::Mut { allow_two_phase_borrow: match allow_two_phase_borrow {
669+
AllowTwoPhase::Yes => true,
670+
AllowTwoPhase::No => false
671+
}},
668672
AutoBorrowMutability::Immutable =>
669673
BorrowKind::Shared,
670674
}

src/librustc_typeck/check/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use hir::def::Def;
1616
use hir::def_id::{DefId, LOCAL_CRATE};
1717
use rustc::{infer, traits};
1818
use rustc::ty::{self, TyCtxt, TypeFoldable, Ty};
19-
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
19+
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
2020
use syntax::abi;
2121
use syntax::symbol::Symbol;
2222
use syntax_pos::Span;
@@ -182,7 +182,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
182182
// For initial two-phase borrow
183183
// deployment, conservatively omit
184184
// overloaded function call ops.
185-
allow_two_phase_borrow: false,
185+
allow_two_phase_borrow: AllowTwoPhase::No,
186186
}
187187
};
188188
autoref = Some(Adjustment {

src/librustc_typeck/check/coercion.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
434434
let mutbl = match mt_b.mutbl {
435435
hir::MutImmutable => AutoBorrowMutability::Immutable,
436436
hir::MutMutable => AutoBorrowMutability::Mutable {
437-
allow_two_phase_borrow: match self.allow_two_phase {
438-
AllowTwoPhase::Yes => true,
439-
AllowTwoPhase::No => false
440-
},
437+
allow_two_phase_borrow: self.allow_two_phase,
441438
}
442439
};
443440
adjustments.push(Adjustment {
@@ -486,7 +483,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
486483
// We don't allow two-phase borrows here, at least for initial
487484
// implementation. If it happens that this coercion is a function argument,
488485
// the reborrow in coerce_borrowed_ptr will pick it up.
489-
allow_two_phase_borrow: false,
486+
allow_two_phase_borrow: AllowTwoPhase::No,
490487
}
491488
};
492489
Some((Adjustment {

src/librustc_typeck/check/method/confirm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::ty::subst::Substs;
1717
use rustc::traits;
1818
use rustc::ty::{self, Ty};
1919
use rustc::ty::subst::Subst;
20-
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, OverloadedDeref};
20+
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, OverloadedDeref};
2121
use rustc::ty::fold::TypeFoldable;
2222
use rustc::infer::{self, InferOk};
2323
use syntax_pos::Span;
@@ -170,7 +170,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
170170
hir::MutMutable => AutoBorrowMutability::Mutable {
171171
// Method call receivers are the primary use case
172172
// for two-phase borrows.
173-
allow_two_phase_borrow: true,
173+
allow_two_phase_borrow: AllowTwoPhase::Yes,
174174
}
175175
};
176176
adjustments.push(Adjustment {
@@ -544,7 +544,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
544544
// For initial two-phase borrow
545545
// deployment, conservatively omit
546546
// overloaded operators.
547-
allow_two_phase_borrow: false,
547+
allow_two_phase_borrow: AllowTwoPhase::No,
548548
}
549549
};
550550
adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(region, mutbl));

src/librustc_typeck/check/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2341,12 +2341,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
23412341
let mutbl = match mt.mutbl {
23422342
hir::MutImmutable => AutoBorrowMutability::Immutable,
23432343
hir::MutMutable => AutoBorrowMutability::Mutable {
2344-
// FIXME (#46747): arguably indexing is
2345-
// "just another kind of call"; perhaps it
2346-
// would be more consistent to allow
2347-
// two-phase borrows for .index()
2348-
// receivers here.
2349-
allow_two_phase_borrow: false,
2344+
// Indexing can be desugared to a method call,
2345+
// so maybe we could use two-phase here.
2346+
// See the documentation of AllowTwoPhase for why that's
2347+
// not the case today.
2348+
allow_two_phase_borrow: AllowTwoPhase::No,
23502349
}
23512350
};
23522351
adjustments.push(Adjustment {
@@ -3647,7 +3646,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
36473646
// (It shouldn't actually matter for unary ops whether
36483647
// we enable two-phase borrows or not, since a unary
36493648
// op has no additional operands.)
3650-
allow_two_phase_borrow: false,
3649+
allow_two_phase_borrow: AllowTwoPhase::No,
36513650
}
36523651
};
36533652
self.apply_adjustments(oprnd, vec![Adjustment {

src/librustc_typeck/check/op.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{FnCtxt, Needs};
1414
use super::method::MethodCallee;
1515
use rustc::ty::{self, Ty, TypeFoldable, TypeVariants};
1616
use rustc::ty::TypeVariants::{TyStr, TyRef, TyAdt};
17-
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
17+
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
1818
use rustc::infer::type_variable::TypeVariableOrigin;
1919
use errors;
2020
use syntax_pos::Span;
@@ -206,7 +206,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
206206
hir::MutMutable => AutoBorrowMutability::Mutable {
207207
// Allow two-phase borrows for binops in initial deployment
208208
// since they desugar to methods
209-
allow_two_phase_borrow: true,
209+
allow_two_phase_borrow: AllowTwoPhase::Yes,
210210
}
211211
};
212212
let autoref = Adjustment {
@@ -223,7 +223,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
223223
hir::MutMutable => AutoBorrowMutability::Mutable {
224224
// Allow two-phase borrows for binops in initial deployment
225225
// since they desugar to methods
226-
allow_two_phase_borrow: true,
226+
allow_two_phase_borrow: AllowTwoPhase::Yes,
227227
}
228228
};
229229
let autoref = Adjustment {

0 commit comments

Comments
 (0)