Skip to content

Commit bdcacb3

Browse files
csmoespastorino
authored andcommitted
add prefix method for neoplace
1 parent 5779b68 commit bdcacb3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/librustc/mir/tcx.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,35 @@ impl<'tcx> NeoPlace<'tcx> {
307307
None
308308
}
309309
}
310+
311+
// for a place_elem returns it's prefix path
312+
// Base.[a, b, c]
313+
// ^-- place_elem
314+
// ^^^^^^^-- prefix
315+
pub fn prefix<'cx, 'gcx>(
316+
&self,
317+
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
318+
elem_index: usize,
319+
) -> Self {
320+
// only works for place with projections
321+
assert!(!self.elems.is_empty());
322+
323+
if elem_index < 1 {
324+
// Base.[a]
325+
// ^-- elems[0]
326+
Self {
327+
base: self.clone().base,
328+
elems: List::empty(),
329+
}
330+
} else {
331+
Self {
332+
base: self.clone().base,
333+
elems: tcx.mk_place_elems(
334+
self.elems.iter().cloned().take(elem_index)
335+
)
336+
}
337+
}
338+
}
310339
}
311340

312341
pub enum RvalueInitializationState {

0 commit comments

Comments
 (0)