diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-10-12 17:19:19 +0000 | 
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-10-21 10:30:16 +0000 | 
| commit | 90e6d2995581b9f03be52ed7fa92fa6a5b981294 (patch) | |
| tree | 9be37452c6611ac037f632a1b8419db0f63df095 /compiler/rustc_mir_dataflow/src/move_paths/mod.rs | |
| parent | 8d535070a2e641889c9e51c0d093c01124bef5b0 (diff) | |
| download | rust-90e6d2995581b9f03be52ed7fa92fa6a5b981294.tar.gz rust-90e6d2995581b9f03be52ed7fa92fa6a5b981294.zip | |
Avoid using a magic value for untracked locals.
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/move_paths/mod.rs')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/move_paths/mod.rs | 13 | 
1 files changed, 8 insertions, 5 deletions
| diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs index 389deb7b355..fff7d12ec48 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs @@ -290,7 +290,7 @@ impl Init { /// Tables mapping from a place to its MovePathIndex. #[derive(Debug)] pub struct MovePathLookup<'tcx> { - locals: IndexVec<Local, MovePathIndex>, + locals: IndexVec<Local, Option<MovePathIndex>>, /// projections are made from a base-place and a projection /// elem. The base-place will have a unique MovePathIndex; we use @@ -317,7 +317,9 @@ impl<'tcx> MovePathLookup<'tcx> { // unknown place, but will rather return the nearest available // parent. pub fn find(&self, place: PlaceRef<'tcx>) -> LookupResult { - let mut result = self.find_local(place.local); + let Some(mut result) = self.find_local(place.local) else { + return LookupResult::Parent(None); + }; for (_, elem) in self.un_derefer.iter_projections(place) { if let Some(&subpath) = self.projections.get(&(result, elem.lift())) { @@ -331,7 +333,7 @@ impl<'tcx> MovePathLookup<'tcx> { } #[inline] - pub fn find_local(&self, local: Local) -> MovePathIndex { + pub fn find_local(&self, local: Local) -> Option<MovePathIndex> { self.locals[local] } @@ -339,8 +341,8 @@ impl<'tcx> MovePathLookup<'tcx> { /// `MovePathIndex`es. pub fn iter_locals_enumerated( &self, - ) -> impl DoubleEndedIterator<Item = (Local, MovePathIndex)> + ExactSizeIterator + '_ { - self.locals.iter_enumerated().map(|(l, &idx)| (l, idx)) + ) -> impl DoubleEndedIterator<Item = (Local, MovePathIndex)> + '_ { + self.locals.iter_enumerated().filter_map(|(l, &idx)| Some((l, idx?))) } } @@ -373,6 +375,7 @@ pub enum IllegalMoveOriginKind<'tcx> { pub enum MoveError<'tcx> { IllegalMove { cannot_move_out_of: IllegalMoveOrigin<'tcx> }, UnionMove { path: MovePathIndex }, + UntrackedLocal, } impl<'tcx> MoveError<'tcx> { | 
