diff options
| author | bobtwinkles <srkoser+GitHub@gmail.com> | 2018-03-28 04:08:03 -0400 |
|---|---|---|
| committer | bobtwinkles <srkoser+GitHub@gmail.com> | 2018-03-28 04:08:03 -0400 |
| commit | d64bd2afc3ee46b9167bb06b3bdacd3bd79add7e (patch) | |
| tree | a48d76ca23a2df031e47b1dbdc02073247889f1f | |
| parent | 96ae0ee382a32d8218da454dc4fd2b2a6fa37c4a (diff) | |
| download | rust-d64bd2afc3ee46b9167bb06b3bdacd3bd79add7e.tar.gz rust-d64bd2afc3ee46b9167bb06b3bdacd3bd79add7e.zip | |
Push AllowTwoPhase down to the HAIR level
For consistency, use AllowTwoPhase everywhere between the frontend and MIR.
| -rw-r--r-- | src/librustc/ich/impls_ty.rs | 4 | ||||
| -rw-r--r-- | src/librustc/ty/adjustment.rs | 3 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 6 | ||||
| -rw-r--r-- | src/librustc_typeck/check/callee.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/check/coercion.rs | 7 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/confirm.rs | 6 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 13 | ||||
| -rw-r--r-- | src/librustc_typeck/check/op.rs | 6 |
8 files changed, 27 insertions, 22 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 9a442e05299..89b8bfcd4ca 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -188,6 +188,10 @@ for ty::adjustment::Adjust<'gcx> { impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target }); impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl }); impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region }); +impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase { + Yes, + No +}); impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability { fn hash_stable<W: StableHasherResult>(&self, diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index edd6d56759d..a0c31e8b509 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -131,6 +131,7 @@ impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> { /// new code via two-phase borrows, so we try to limit where we create two-phase /// capable mutable borrows. /// See #49434 for tracking. +#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] pub enum AllowTwoPhase { Yes, No @@ -138,7 +139,7 @@ pub enum AllowTwoPhase { #[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] pub enum AutoBorrowMutability { - Mutable { allow_two_phase_borrow: bool }, + Mutable { allow_two_phase_borrow: AllowTwoPhase }, Immutable, } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 62d1b43d625..5b373908480 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -662,9 +662,13 @@ trait ToBorrowKind { fn to_borrow_kind(&self) -> BorrowKind; } impl ToBorrowKind for AutoBorrowMutability { fn to_borrow_kind(&self) -> BorrowKind { + use rustc::ty::adjustment::AllowTwoPhase; match *self { AutoBorrowMutability::Mutable { allow_two_phase_borrow } => - BorrowKind::Mut { allow_two_phase_borrow }, + BorrowKind::Mut { allow_two_phase_borrow: match allow_two_phase_borrow { + AllowTwoPhase::Yes => true, + AllowTwoPhase::No => false + }}, AutoBorrowMutability::Immutable => BorrowKind::Shared, } diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 3d61ffe3933..b1fb0938698 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -16,7 +16,7 @@ use hir::def::Def; use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::{infer, traits}; use rustc::ty::{self, TyCtxt, TypeFoldable, Ty}; -use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability}; +use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use syntax::abi; use syntax::symbol::Symbol; use syntax_pos::Span; @@ -182,7 +182,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // For initial two-phase borrow // deployment, conservatively omit // overloaded function call ops. - allow_two_phase_borrow: false, + allow_two_phase_borrow: AllowTwoPhase::No, } }; autoref = Some(Adjustment { diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 8b4b4bab7c4..a956dd9a4ee 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -434,10 +434,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { let mutbl = match mt_b.mutbl { hir::MutImmutable => AutoBorrowMutability::Immutable, hir::MutMutable => AutoBorrowMutability::Mutable { - allow_two_phase_borrow: match self.allow_two_phase { - AllowTwoPhase::Yes => true, - AllowTwoPhase::No => false - }, + allow_two_phase_borrow: self.allow_two_phase, } }; adjustments.push(Adjustment { @@ -486,7 +483,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { // We don't allow two-phase borrows here, at least for initial // implementation. If it happens that this coercion is a function argument, // the reborrow in coerce_borrowed_ptr will pick it up. - allow_two_phase_borrow: false, + allow_two_phase_borrow: AllowTwoPhase::No, } }; Some((Adjustment { diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index b777ac30920..8a37c11f191 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -17,7 +17,7 @@ use rustc::ty::subst::Substs; use rustc::traits; use rustc::ty::{self, Ty}; use rustc::ty::subst::Subst; -use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, OverloadedDeref}; +use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, OverloadedDeref}; use rustc::ty::fold::TypeFoldable; use rustc::infer::{self, InferOk}; use syntax_pos::Span; @@ -170,7 +170,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { hir::MutMutable => AutoBorrowMutability::Mutable { // Method call receivers are the primary use case // for two-phase borrows. - allow_two_phase_borrow: true, + allow_two_phase_borrow: AllowTwoPhase::Yes, } }; adjustments.push(Adjustment { @@ -544,7 +544,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // For initial two-phase borrow // deployment, conservatively omit // overloaded operators. - allow_two_phase_borrow: false, + allow_two_phase_borrow: AllowTwoPhase::No, } }; adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(region, mutbl)); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0e1d3fdbb97..a377ff4d29d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2341,12 +2341,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let mutbl = match mt.mutbl { hir::MutImmutable => AutoBorrowMutability::Immutable, hir::MutMutable => AutoBorrowMutability::Mutable { - // FIXME (#46747): arguably indexing is - // "just another kind of call"; perhaps it - // would be more consistent to allow - // two-phase borrows for .index() - // receivers here. - allow_two_phase_borrow: false, + // Indexing can be desugared to a method call, + // so maybe we could use two-phase here. + // See the documentation of AllowTwoPhase for why that's + // not the case today. + allow_two_phase_borrow: AllowTwoPhase::No, } }; adjustments.push(Adjustment { @@ -3647,7 +3646,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // (It shouldn't actually matter for unary ops whether // we enable two-phase borrows or not, since a unary // op has no additional operands.) - allow_two_phase_borrow: false, + allow_two_phase_borrow: AllowTwoPhase::No, } }; self.apply_adjustments(oprnd, vec