Skip to content

Commit 03d1508

Browse files
committed
don't activate borrows that are already activated
1 parent e6376a1 commit 03d1508

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/librustc_mir/borrow_check/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
317317
}
318318

319319
fn visit_block_entry(&mut self, bb: BasicBlock, flow_state: &Self::FlowState) {
320-
debug!("MirBorrowckCtxt::process_block({:?}): {}", bb, flow_state);
320+
debug!("MirBorrowckCtxt::visit_block_entry({:?}): {}", bb, flow_state);
321321
}
322322

323323
fn visit_statement_entry(
@@ -327,7 +327,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
327327
flow_state: &Self::FlowState,
328328
) {
329329
debug!(
330-
"MirBorrowckCtxt::process_statement({:?}, {:?}): {}",
330+
"MirBorrowckCtxt::visit_statement_entry({:?}, {:?}): {}",
331331
location,
332332
stmt,
333333
flow_state
@@ -1127,6 +1127,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
11271127
BorrowKind::Unique | BorrowKind::Mut => {}
11281128
}
11291129

1130+
// If this is already activated, no need to do further checks.
1131+
if flow_state.borrows.contains(&gen) {
1132+
return;
1133+
}
1134+
11301135
self.access_place(
11311136
ContextKind::Activation.new(location),
11321137
(&borrow.borrowed_place, span),

src/test/ui/issue-45157.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,5 @@ error[E0502]: cannot borrow `u.z.c` as immutable because it is also borrowed as
77
37 | let nref = &u.z.c;
88
| ^^^^^^ immutable borrow occurs here
99

10-
error[E0502]: cannot borrow `u.s.a` as mutable because it is also borrowed as immutable
11-
--> $DIR/issue-45157.rs:39:27
12-
|
13-
37 | let nref = &u.z.c;
14-
| ------ immutable borrow occurs here
15-
38 | //~^ ERROR cannot borrow `u.z.c` as immutable because it is also borrowed as mutable [E0502]
16-
39 | println!("{} {}", mref, nref)
17-
| ^^^^ mutable borrow occurs here
18-
19-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2011

0 commit comments

Comments
 (0)