Skip to content

Commit 2c840ae

Browse files
committed
Use normal mutable borrows in MIR match lowering
1 parent 5407fbd commit 2c840ae

File tree

10 files changed

+227
-308
lines changed

10 files changed

+227
-308
lines changed

src/librustc/ich/impls_mir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ impl_stable_hash_for!(impl<'gcx> for enum mir::StatementKind<'gcx> [ mir::Statem
196196
});
197197

198198
impl_stable_hash_for!(enum mir::RetagKind { FnEntry, TwoPhase, Raw, Default });
199-
impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet });
199+
impl_stable_hash_for!(enum mir::FakeReadCause {
200+
ForMatchGuard,
201+
ForMatchedPlace,
202+
ForGuardBinding,
203+
ForLet
204+
});
200205

201206
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::Place<'gcx> {
202207
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/mir/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,17 +1823,22 @@ pub enum RetagKind {
18231823
/// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists.
18241824
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)]
18251825
pub enum FakeReadCause {
1826-
/// Inject a fake read of the borrowed input at the start of each arm's
1827-
/// pattern testing code.
1826+
/// Inject a fake read of the borrowed input at the end of each guards
1827+
/// code.
18281828
///
1829-
/// This should ensure that you cannot change the variant for an enum
1830-
/// while you are in the midst of matching on it.
1829+
/// This should ensure that you cannot change the variant for an enum while
1830+
/// you are in the midst of matching on it.
18311831
ForMatchGuard,
18321832

18331833
/// `let x: !; match x {}` doesn't generate any read of x so we need to
18341834
/// generate a read of x to check that it is initialized and safe.
18351835
ForMatchedPlace,
18361836

1837+
/// A fake read of the RefWithinGuard version of a bind-by-value variable
1838+
/// in a match guard to ensure that it's value hasn't change by the time
1839+
/// we create the OutsideGuard version.
1840+
ForGuardBinding,
1841+
18371842
/// Officially, the semantics of
18381843
///
18391844
/// `let pattern = <expr>;`

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
998998
}
999999

10001000
(Read(_), BorrowKind::Shared) | (Reservation(..), BorrowKind::Shared)
1001-
| (Read(_), BorrowKind::Shallow) | (Reservation(..), BorrowKind::Shallow) => {
1001+
| (Read(_), BorrowKind::Shallow) | (Reservation(..), BorrowKind::Shallow)
1002+
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Unique)
1003+
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
10021004
Control::Continue
10031005
}
10041006

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,8 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
7878
JustWrite
7979
);
8080
}
81-
StatementKind::FakeRead(_, ref place) => {
82-
self.access_place(
83-
ContextKind::FakeRead.new(location),
84-
place,
85-
(Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
86-
LocalMutationIsAllowed::No,
87-
);
81+
StatementKind::FakeRead(_, _) => {
82+
// Only relavent for initialized/liveness/safety checks.
8883
}
8984
StatementKind::SetDiscriminant {
9085
ref place,
@@ -438,7 +433,9 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
438433
}
439434

440435
(Read(_), BorrowKind::Shallow) | (Reservation(..), BorrowKind::Shallow)
441-
| (Read(_), BorrowKind::Shared) | (Reservation(..), BorrowKind::Shared) => {
436+
| (Read(_), BorrowKind::Shared) | (Reservation(..), BorrowKind::Shared)
437+
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Unique)
438+
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
442439
// Reads/reservations don't invalidate shared or shallow borrows
443440
}
444441

src/librustc_mir/build/block.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use rustc::mir::*;
66
use rustc::hir;
77
use syntax_pos::Span;
88

9-
use std::slice;
10-
119
impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1210
pub fn ast_block(&mut self,
1311
destination: &Place<'tcx>,
@@ -125,7 +123,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
125123
None,
126124
remainder_span,
127125
lint_level,
128-
slice::from_ref(&pattern),
126+
&pattern,
129127
ArmHasGuard(false),
130128
Some((None, initializer_span)),
131129
);
@@ -138,7 +136,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
138136
}));
139137
} else {
140138
scope = this.declare_bindings(
141-
None, remainder_span, lint_level, slice::from_ref(&pattern),
139+
None, remainder_span, lint_level, &pattern,
142140
ArmHasGuard(false), None);
143141

144142
debug!("ast_block_stmts: pattern={:?}", pattern);

0 commit comments

Comments
 (0)