]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_mir_dataflow/src/un_derefer.rs
Rollup merge of #107719 - WaffleLapkin:de-arena-allocates-you-UwU, r=cjgillot
[rust.git] / compiler / rustc_mir_dataflow / src / un_derefer.rs
1 use rustc_data_structures::fx::FxHashMap;
2 use rustc_middle::mir::*;
3 use rustc_middle::ty::TyCtxt;
4
5 /// Used for reverting changes made by `DerefSeparator`
6 pub struct UnDerefer<'tcx> {
7     pub tcx: TyCtxt<'tcx>,
8     pub derefer_sidetable: FxHashMap<Local, Place<'tcx>>,
9 }
10
11 impl<'tcx> UnDerefer<'tcx> {
12     #[inline]
13     pub fn derefer(&self, place: PlaceRef<'tcx>, body: &Body<'tcx>) -> Option<Place<'tcx>> {
14         let reffed = self.derefer_sidetable.get(&place.local)?;
15
16         let new_place = reffed.project_deeper(place.projection, self.tcx);
17         if body.local_decls[new_place.local].is_deref_temp() {
18             return self.derefer(new_place.as_ref(), body);
19         }
20         Some(new_place)
21     }
22 }