merge BorrowKind::Unique
into BorrowKind::Mut
This commit is contained in:
parent
6fc0273b5a
commit
8fb4c41f35
21 changed files with 109 additions and 105 deletions
|
@ -442,7 +442,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
match upvar.kind {
|
||||
ExprKind::Borrow {
|
||||
borrow_kind:
|
||||
BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
BorrowKind::Mut { kind: MutBorrowKind::Default },
|
||||
arg,
|
||||
} => unpack!(
|
||||
block = this.limit_capture_mutability(
|
||||
|
@ -795,8 +795,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
};
|
||||
|
||||
let borrow_kind = match mutability {
|
||||
Mutability::Not => BorrowKind::Unique,
|
||||
Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
Mutability::Not => BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture },
|
||||
Mutability::Mut => BorrowKind::Mut { kind: MutBorrowKind::Default },
|
||||
};
|
||||
|
||||
let arg_place = arg_place_builder.to_place(this);
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::errors::*;
|
|||
use rustc_middle::thir::visit::{self, Visitor};
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::mir::BorrowKind;
|
||||
use rustc_middle::mir::{BorrowKind, MutBorrowKind};
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
|
||||
|
@ -254,7 +254,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
);
|
||||
};
|
||||
match borrow_kind {
|
||||
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique => {
|
||||
BorrowKind::Shallow
|
||||
| BorrowKind::Shared
|
||||
| BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture } => {
|
||||
if !ty.is_freeze(self.tcx, self.param_env) {
|
||||
self.requires_unsafe(pat.span, BorrowOfLayoutConstrainedField);
|
||||
}
|
||||
|
@ -440,15 +442,19 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
visit::walk_expr(&mut visitor, expr);
|
||||
if visitor.found {
|
||||
match borrow_kind {
|
||||
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique
|
||||
BorrowKind::Shallow
|
||||
| BorrowKind::Shared
|
||||
| BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture }
|
||||
if !self.thir[arg].ty.is_freeze(self.tcx, self.param_env) =>
|
||||
{
|
||||
self.requires_unsafe(expr.span, BorrowOfLayoutConstrainedField)
|
||||
}
|
||||
BorrowKind::Mut { .. } => {
|
||||
self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField)
|
||||
}
|
||||
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique => {}
|
||||
BorrowKind::Mut {
|
||||
kind: MutBorrowKind::Default | MutBorrowKind::TwoPhaseBorrow,
|
||||
} => self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField),
|
||||
BorrowKind::Shallow
|
||||
| BorrowKind::Shared
|
||||
| BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1095,8 +1095,12 @@ impl<'tcx> Cx<'tcx> {
|
|||
ty::UpvarCapture::ByRef(upvar_borrow) => {
|
||||
let borrow_kind = match upvar_borrow {
|
||||
ty::BorrowKind::ImmBorrow => BorrowKind::Shared,
|
||||
ty::BorrowKind::UniqueImmBorrow => BorrowKind::Unique,
|
||||
ty::BorrowKind::MutBorrow => BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
ty::BorrowKind::UniqueImmBorrow => {
|
||||
BorrowKind::Mut { kind: mir::MutBorrowKind::ClosureCapture }
|
||||
}
|
||||
ty::BorrowKind::MutBorrow => {
|
||||
BorrowKind::Mut { kind: mir::MutBorrowKind::Default }
|
||||
}
|
||||
};
|
||||
Expr {
|
||||
temp_lifetime,
|
||||
|
@ -1132,9 +1136,9 @@ impl ToBorrowKind for AutoBorrowMutability {
|
|||
use rustc_middle::ty::adjustment::AllowTwoPhase;
|
||||
match *self {
|
||||
AutoBorrowMutability::Mut { allow_two_phase_borrow } => BorrowKind::Mut {
|
||||
allow_two_phase_borrow: match allow_two_phase_borrow {
|
||||
AllowTwoPhase::Yes => true,
|
||||
AllowTwoPhase::No => false,
|
||||
kind: match allow_two_phase_borrow {
|
||||
AllowTwoPhase::Yes => mir::MutBorrowKind::TwoPhaseBorrow,
|
||||
AllowTwoPhase::No => mir::MutBorrowKind::Default,
|
||||
},
|
||||
},
|
||||
AutoBorrowMutability::Not => BorrowKind::Shared,
|
||||
|
@ -1145,7 +1149,7 @@ impl ToBorrowKind for AutoBorrowMutability {
|
|||
impl ToBorrowKind for hir::Mutability {
|
||||
fn to_borrow_kind(&self) -> BorrowKind {
|
||||
match *self {
|
||||
hir::Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
|
||||
hir::Mutability::Not => BorrowKind::Shared,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
ty::BindByValue(mutbl) => (mutbl, BindingMode::ByValue),
|
||||
ty::BindByReference(hir::Mutability::Mut) => (
|
||||
Mutability::Not,
|
||||
BindingMode::ByRef(BorrowKind::Mut { allow_two_phase_borrow: false }),
|
||||
BindingMode::ByRef(BorrowKind::Mut { kind: mir::MutBorrowKind::Default }),
|
||||
),
|
||||
ty::BindByReference(hir::Mutability::Not) => {
|
||||
(Mutability::Not, BindingMode::ByRef(BorrowKind::Shared))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue