Skip to content

Commit 5779b68

Browse files
csmoespastorino
authored andcommitted
implement construct method for NeoPlace
1 parent eab6d54 commit 5779b68

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

src/librustc/mir/mod.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,91 @@ impl<'tcx> Place<'tcx> {
20902090
}
20912091
}
20922092

2093+
impl<'tcx> NeoPlace<'tcx> {
2094+
pub fn local(local: Local) -> Self {
2095+
Self {
2096+
base: PlaceBase::Local(local),
2097+
elems: List::empty(),
2098+
}
2099+
}
2100+
2101+
pub fn static_(static_: Static<'tcx>) -> Self {
2102+
Self {
2103+
base: PlaceBase::Static(box static_),
2104+
elems: List::empty(),
2105+
}
2106+
}
2107+
2108+
pub fn promoted(promoted: Promoted, ty: Ty<'tcx>) -> Self {
2109+
Self {
2110+
base: PlaceBase::Promoted(box (promoted, ty)),
2111+
elems: List::empty(),
2112+
}
2113+
}
2114+
2115+
pub fn field(
2116+
self,
2117+
tcx: TyCtxt<'_, '_, 'tcx>,
2118+
f: Field,
2119+
ty: Ty<'tcx>,
2120+
) -> Self {
2121+
self.elem(tcx, ProjectionElem::Field(f, ty))
2122+
}
2123+
2124+
pub fn deref(self, tcx: TyCtxt<'_, '_, 'tcx>) -> Self {
2125+
self.elem(tcx, ProjectionElem::Deref)
2126+
}
2127+
2128+
pub fn downcast(
2129+
self,
2130+
tcx: TyCtxt<'_, '_, 'tcx>,
2131+
adt_def: &'tcx AdtDef,
2132+
variant_index: usize,
2133+
) -> Self {
2134+
self.elem(tcx, ProjectionElem::Downcast(adt_def, variant_index))
2135+
}
2136+
2137+
pub fn index(self, tcx: TyCtxt<'_, '_, 'tcx>, index: Local) -> Self {
2138+
self.elem(tcx, ProjectionElem::Index(index))
2139+
}
2140+
2141+
pub fn constant_index(
2142+
self,
2143+
tcx: TyCtxt<'_, '_, 'tcx>,
2144+
offset: u32,
2145+
min_length: u32,
2146+
from_end: bool,
2147+
) -> Self {
2148+
self.elem(tcx, ProjectionElem::ConstantIndex {
2149+
offset, min_length, from_end,
2150+
})
2151+
}
2152+
2153+
pub fn subslice(
2154+
self,
2155+
tcx: TyCtxt<'_, '_, 'tcx>,
2156+
from: u32,
2157+
to: u32,
2158+
) -> Self {
2159+
self.elem(tcx, ProjectionElem::Subslice {
2160+
from, to,
2161+
})
2162+
}
2163+
2164+
fn elem(
2165+
self,
2166+
tcx: TyCtxt<'_, '_, 'tcx>,
2167+
elem: PlaceElem<'tcx>,
2168+
) -> Self {
2169+
Self {
2170+
base: self.base,
2171+
elems: tcx.mk_place_elems(
2172+
self.elems.iter().cloned().chain(iter::once(elem))
2173+
),
2174+
}
2175+
}
2176+
}
2177+
20932178
impl<'tcx> Debug for Place<'tcx> {
20942179
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
20952180
use self::Place::*;

0 commit comments

Comments
 (0)