Skip to content

Commit cab7af9

Browse files
committed
Check for ConstantIndex move paths correctly in borrowck
1 parent 96dc03b commit cab7af9

File tree

1 file changed

+6
-15
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+6
-15
lines changed

src/librustc_mir/borrow_check/mod.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1738,25 +1738,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17381738
/// static variable, as we do not track those in the MoveData.
17391739
fn move_path_closest_to(
17401740
&mut self,
1741-
place: PlaceRef<'cx, 'tcx>,
1741+
place: PlaceRef<'_, 'tcx>,
17421742
) -> Result<(PlaceRef<'cx, 'tcx>, MovePathIndex), NoMovePathFound> {
1743-
let mut last_prefix = place.base;
1744-
1745-
for prefix in self.prefixes(place, PrefixSet::All) {
1746-
if let Some(mpi) = self.move_path_for_place(prefix) {
1747-
return Ok((prefix, mpi));
1748-
}
1749-
1750-
last_prefix = prefix.base;
1751-
}
1752-
1753-
match last_prefix {
1754-
PlaceBase::Local(_) => panic!("should have move path for every Local"),
1755-
PlaceBase::Static(_) => Err(NoMovePathFound::ReachedStatic),
1743+
match self.move_data.rev_lookup.find(place) {
1744+
LookupResult::Parent(Some(mpi))
1745+
| LookupResult::Exact(mpi) => Ok((self.move_data.move_paths[mpi].place.as_ref(), mpi)),
1746+
LookupResult::Parent(None) => Err(NoMovePathFound::ReachedStatic),
17561747
}
17571748
}
17581749

1759-
fn move_path_for_place(&mut self, place: PlaceRef<'cx, 'tcx>) -> Option<MovePathIndex> {
1750+
fn move_path_for_place(&mut self, place: PlaceRef<'_, 'tcx>) -> Option<MovePathIndex> {
17601751
// If returns None, then there is no move path corresponding
17611752
// to a direct owner of `place` (which means there is nothing
17621753
// that borrowck tracks for its analysis).

0 commit comments

Comments
 (0)