Skip to content

Commit aa3780b

Browse files
committed
Treat two-phase borrow reservations as mutable accesses
1 parent b57fe74 commit aa3780b

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

src/librustc_codegen_llvm/abi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
266266
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
267267
}
268268
PassMode::Direct(_) | PassMode::Indirect(_, None) | PassMode::Cast(_) => {
269-
self.store(bx, next(), dst);
269+
let next_arg = next();
270+
self.store(bx, next_arg, dst);
270271
}
271272
}
272273
}

src/librustc_mir/borrow_check/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
997997
Control::Continue
998998
}
999999

1000-
(Read(_), BorrowKind::Shared) | (Reservation(..), BorrowKind::Shared)
1001-
| (Read(_), BorrowKind::Shallow) | (Reservation(..), BorrowKind::Shallow)
1000+
(Read(_), BorrowKind::Shared)
1001+
| (Read(_), BorrowKind::Shallow)
10021002
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Unique)
10031003
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
10041004
Control::Continue
@@ -1028,8 +1028,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10281028
Control::Break
10291029
}
10301030

1031-
(Reservation(kind), BorrowKind::Unique)
1032-
| (Reservation(kind), BorrowKind::Mut { .. })
1031+
(Reservation(kind), _)
10331032
| (Activation(kind, _), _)
10341033
| (Write(kind), _) => {
10351034
match rw {

src/librustc_mir/borrow_check/nll/invalidation.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
432432
// have already taken the reservation
433433
}
434434

435-
(Read(_), BorrowKind::Shallow) | (Reservation(..), BorrowKind::Shallow)
436-
| (Read(_), BorrowKind::Shared) | (Reservation(..), BorrowKind::Shared)
435+
(Read(_), BorrowKind::Shallow)
436+
| (Read(_), BorrowKind::Shared)
437437
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Unique)
438438
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
439439
// Reads/reservations don't invalidate shared or shallow borrows
@@ -452,16 +452,15 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
452452
this.generate_invalidates(borrow_index, context.loc);
453453
}
454454

455-
(Reservation(_), BorrowKind::Unique)
456-
| (Reservation(_), BorrowKind::Mut { .. })
457-
| (Activation(_, _), _)
458-
| (Write(_), _) => {
459-
// unique or mutable borrows are invalidated by writes.
460-
// Reservations count as writes since we need to check
461-
// that activating the borrow will be OK
462-
// FIXME(bob_twinkles) is this actually the right thing to do?
463-
this.generate_invalidates(borrow_index, context.loc);
464-
}
455+
(Reservation(_), _)
456+
| (Activation(_, _), _)
457+
| (Write(_), _) => {
458+
// unique or mutable borrows are invalidated by writes.
459+
// Reservations count as writes since we need to check
460+
// that activating the borrow will be OK
461+
// FIXME(bob_twinkles) is this actually the right thing to do?
462+
this.generate_invalidates(borrow_index, context.loc);
463+
}
465464
}
466465
Control::Continue
467466
},

src/librustc_mir/transform/add_retag.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl MirPass for AddRetag {
165165
if src_ty.is_region_ptr() {
166166
// The only `Misc` casts on references are those creating raw pointers.
167167
assert!(dest_ty.is_unsafe_ptr());
168-
(RetagKind::Raw, place)
168+
(RetagKind::Raw, place.clone())
169169
} else {
170170
// Some other cast, no retag
171171
continue
@@ -183,7 +183,7 @@ impl MirPass for AddRetag {
183183
_ =>
184184
RetagKind::Default,
185185
};
186-
(kind, place)
186+
(kind, place.clone())
187187
}
188188
// Do nothing for the rest
189189
_ => continue,
@@ -192,7 +192,7 @@ impl MirPass for AddRetag {
192192
let source_info = block_data.statements[i].source_info;
193193
block_data.statements.insert(i+1, Statement {
194194
source_info,
195-
kind: StatementKind::Retag(retag_kind, place.clone()),
195+
kind: StatementKind::Retag(retag_kind, place),
196196
});
197197
}
198198
}

src/libsyntax_ext/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ impl<'a, 'b> Context<'a, 'b> {
347347

348348
Named(name) => {
349349
match self.names.get(&name) {
350-
Some(idx) => {
350+
Some(&idx) => {
351351
// Treat as positional arg.
352-
self.verify_arg_type(Exact(*idx), ty)
352+
self.verify_arg_type(Exact(idx), ty)
353353
}
354354
None => {
355355
let msg = format!("there is no argument named `{}`", name);

0 commit comments

Comments
 (0)