Add AutoBorrowMutability; its like hir::Mutability but w/ two-phase borrow info too.
Namely, the mutable borrows also carries a flag indicating whether they should support two-phase borrows. This allows us to thread down, from the point of the borrow's introduction, whether the particular adjustment that created it is one that yields two-phase mutable borrows.
This commit is contained in:
parent
1855ab7424
commit
c8041dd8ac
11 changed files with 154 additions and 28 deletions
|
|
@ -163,6 +163,20 @@ 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<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrowMutability {
|
||||
fn hash_stable<W: StableHasherResult>(&self,
|
||||
hcx: &mut StableHashingContext<'gcx>,
|
||||
hasher: &mut StableHasher<W>) {
|
||||
mem::discriminant(self).hash_stable(hcx, hasher);
|
||||
match *self {
|
||||
ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => {
|
||||
allow_two_phase_borrow.hash_stable(hcx, hasher);
|
||||
}
|
||||
ty::adjustment::AutoBorrowMutability::Immutable => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
|
||||
|
||||
impl_stable_hash_for!(enum ty::BorrowKind {
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
|
|||
expr.span,
|
||||
cmt_base,
|
||||
r,
|
||||
ty::BorrowKind::from_mutbl(m),
|
||||
ty::BorrowKind::from_mutbl(m.into()),
|
||||
AutoRef);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,10 +119,25 @@ impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum AutoBorrowMutability {
|
||||
Mutable { allow_two_phase_borrow: bool },
|
||||
Immutable,
|
||||
}
|
||||
|
||||
impl From<AutoBorrowMutability> for hir::Mutability {
|
||||
fn from(m: AutoBorrowMutability) -> Self {
|
||||
match m {
|
||||
AutoBorrowMutability::Mutable { .. } => hir::MutMutable,
|
||||
AutoBorrowMutability::Immutable => hir::MutImmutable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
|
||||
pub enum AutoBorrow<'tcx> {
|
||||
/// Convert from T to &T.
|
||||
Ref(ty::Region<'tcx>, hir::Mutability),
|
||||
Ref(ty::Region<'tcx>, AutoBorrowMutability),
|
||||
|
||||
/// Convert from T to *T.
|
||||
RawPtr(hir::Mutability),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue