Skip to content

Commit 86b961a

Browse files
Revert "Only consider places with the same local in each_borrow_involving_path."
This reverts commit 372366d.
1 parent 828bdc2 commit 86b961a

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

compiler/rustc_borrowck/src/invalidation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,15 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
353353
let tcx = self.tcx;
354354
let body = self.body;
355355
let borrow_set = self.borrow_set;
356+
let indices = self.borrow_set.indices();
356357
each_borrow_involving_path(
357358
self,
358359
tcx,
359360
body,
360361
location,
361362
(sd, place),
362363
borrow_set,
363-
|_| true,
364+
indices,
364365
|this, borrow_index, borrow| {
365366
match (rw, borrow.kind) {
366367
// Obviously an activation is compatible with its own

compiler/rustc_borrowck/src/lib.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, Subdiagnost
2323
use rustc_fluent_macro::fluent_messages;
2424
use rustc_hir as hir;
2525
use rustc_hir::def_id::LocalDefId;
26-
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
26+
use rustc_index::bit_set::ChunkedBitSet;
2727
use rustc_index::{IndexSlice, IndexVec};
2828
use rustc_infer::infer::{
2929
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
@@ -42,6 +42,7 @@ use rustc_session::lint::builtin::UNUSED_MUT;
4242
use rustc_span::{Span, Symbol};
4343
use rustc_target::abi::FieldIdx;
4444

45+
use either::Either;
4546
use smallvec::SmallVec;
4647
use std::cell::RefCell;
4748
use std::collections::BTreeMap;
@@ -1034,16 +1035,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10341035
let borrow_set = self.borrow_set.clone();
10351036

10361037
// Use polonius output if it has been enabled.
1037-
let mut polonius_output;
1038-
let borrows_in_scope = if let Some(polonius) = &self.polonius_output {
1038+
let polonius_output = self.polonius_output.clone();
1039+
let borrows_in_scope = if let Some(polonius) = &polonius_output {
10391040
let location = self.location_table.start_index(location);
1040-
polonius_output = BitSet::new_empty(borrow_set.len());
1041-
for &idx in polonius.errors_at(location) {
1042-
polonius_output.insert(idx);
1043-
}
1044-
&polonius_output
1041+
Either::Left(polonius.errors_at(location).iter().copied())
10451042
} else {
1046-
&flow_state.borrows
1043+
Either::Right(flow_state.borrows.iter())
10471044
};
10481045

10491046
each_borrow_involving_path(
@@ -1053,7 +1050,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10531050
location,
10541051
(sd, place_span.0),
10551052
&borrow_set,
1056-
|borrow_index| borrows_in_scope.contains(borrow_index),
1053+
borrows_in_scope,
10571054
|this, borrow_index, borrow| match (rw, borrow.kind) {
10581055
// Obviously an activation is compatible with its own
10591056
// reservation (or even prior activating uses of same

compiler/rustc_borrowck/src/path_utils.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,20 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
3333
_location: Location,
3434
access_place: (AccessDepth, Place<'tcx>),
3535
borrow_set: &BorrowSet<'tcx>,
36-
is_candidate: I,
36+
candidates: I,
3737
mut op: F,
3838
) where
3939
F: FnMut(&mut S, BorrowIndex, &BorrowData<'tcx>) -> Control,
40-
I: Fn(BorrowIndex) -> bool,
40+
I: Iterator<Item = BorrowIndex>,
4141
{
4242
let (access, place) = access_place;
4343

44-
// The number of candidates can be large, but borrows for different locals cannot conflict with
45-
// each other, so we restrict the working set a priori.
46-
let Some(borrows_for_place_base) = borrow_set.local_map.get(&place.local) else { return };
44+
// FIXME: analogous code in check_loans first maps `place` to
45+
// its base_path.
4746

4847
// check for loan restricting path P being used. Accounts for
4948
// borrows of P, P.a.b, etc.
50-
for &i in borrows_for_place_base {
51-
if !is_candidate(i) {
52-
continue;
53-
}
49+
for i in candidates {
5450
let borrowed = &borrow_set[i];
5551

5652
if places_conflict::borrow_conflicts_with_place(

0 commit comments

Comments
 (0)