Skip to content

Commit b04e6c7

Browse files
committed
Make move_path_children_matching closure take a PlaceElem instead of a slice
1 parent 7efee8d commit b04e6c7

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/librustc_mir/dataflow/drop_flag_effects.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
1010
path: MovePathIndex,
1111
mut cond: F)
1212
-> Option<MovePathIndex>
13-
where F: FnMut(&[mir::PlaceElem<'tcx>]) -> bool
13+
where F: FnMut(&mir::PlaceElem<'tcx>) -> bool
1414
{
1515
let mut next_child = move_data.move_paths[path].first_child;
1616
while let Some(child_index) = next_child {
17-
if cond(&move_data.move_paths[child_index].place.projection) {
18-
return Some(child_index)
17+
let move_path_children = &move_data.move_paths[child_index];
18+
if let Some(elem) = move_path_children.place.projection.last() {
19+
if cond(elem) {
20+
return Some(child_index)
21+
}
1922
}
20-
next_child = move_data.move_paths[child_index].next_sibling;
23+
next_child = move_path_children.next_sibling;
2124
}
2225

2326
None

src/librustc_mir/transform/elaborate_drops.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,36 +236,33 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> {
236236
}
237237

238238
fn field_subpath(&self, path: Self::Path, field: Field) -> Option<Self::Path> {
239-
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |p| match p {
240-
[.., ProjectionElem::Field(idx, _)] => *idx == field,
239+
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e {
240+
ProjectionElem::Field(idx, _) => *idx == field,
241241
_ => false,
242242
})
243243
}
244244

245245
fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option<Self::Path> {
246-
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |p| match p {
247-
[.., ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false }] => {
246+
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e {
247+
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: false } => {
248248
*offset == index
249249
}
250-
[.., ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true }] => {
250+
ProjectionElem::ConstantIndex { offset, min_length: _, from_end: true } => {
251251
size - offset == index
252252
}
253253
_ => false,
254254
})
255255
}
256256

257257
fn deref_subpath(&self, path: Self::Path) -> Option<Self::Path> {
258-
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |p| {
259-
match p {
260-
[.., ProjectionElem::Deref] => true,
261-
_ => false
262-
}
258+
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| {
259+
*e == ProjectionElem::Deref
263260
})
264261
}
265262

266263
fn downcast_subpath(&self, path: Self::Path, variant: VariantIdx) -> Option<Self::Path> {
267-
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |p| match p {
268-
[.., ProjectionElem::Downcast(_, idx)] => *idx == variant,
264+
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e {
265+
ProjectionElem::Downcast(_, idx) => *idx == variant,
269266
_ => false
270267
})
271268
}

0 commit comments

Comments
 (0)