Push AllowTwoPhase down to the HAIR level
For consistency, use AllowTwoPhase everywhere between the frontend and MIR.
This commit is contained in:
parent
96ae0ee382
commit
d64bd2afc3
8 changed files with 27 additions and 22 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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![Adjustment {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use super::{FnCtxt, Needs};
|
|||
use super::method::MethodCallee;
|
||||
use rustc::ty::{self, Ty, TypeFoldable, TypeVariants};
|
||||
use rustc::ty::TypeVariants::{TyStr, TyRef, TyAdt};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
|
||||
use rustc::infer::type_variable::TypeVariableOrigin;
|
||||
use errors;
|
||||
use syntax_pos::Span;
|
||||
|
|
@ -206,7 +206,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
// Allow two-phase borrows for binops in initial deployment
|
||||
// since they desugar to methods
|
||||
allow_two_phase_borrow: true,
|
||||
allow_two_phase_borrow: AllowTwoPhase::Yes,
|
||||
}
|
||||
};
|
||||
let autoref = Adjustment {
|
||||
|
|
@ -223,7 +223,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
hir::MutMutable => AutoBorrowMutability::Mutable {
|
||||
// Allow two-phase borrows for binops in initial deployment
|
||||
// since they desugar to methods
|
||||
allow_two_phase_borrow: true,
|
||||
allow_two_phase_borrow: AllowTwoPhase::Yes,
|
||||
}
|
||||
};
|
||||
let autoref = Adjustment {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue