Skip to content

Commit 56773a9

Browse files
committed
refactor PlaceTy::base_ty into a method on PlaceBase
1 parent c1fff48 commit 56773a9

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/librustc/mir/tcx.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ pub enum PlaceTy<'tcx> {
3333
}
3434

3535
impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
36-
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
37-
PlaceTy::Ty { ty }
38-
}
39-
4036
pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
4137
match *self {
4238
PlaceTy::Ty { ty } => ty,
@@ -48,19 +44,6 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
4844
}
4945
}
5046

51-
fn base_ty<T>(local_decls: &T, base: &PlaceBase<'tcx>) -> PlaceTy<'tcx>
52-
where
53-
T: HasLocalDecls<'tcx>,
54-
{
55-
match base {
56-
PlaceBase::Local(index) => PlaceTy::Ty {
57-
ty: local_decls.local_decls()[*index].ty,
58-
},
59-
PlaceBase::Promoted(data) => PlaceTy::Ty { ty: data.1 },
60-
PlaceBase::Static(data) => PlaceTy::Ty { ty: data.ty },
61-
}
62-
}
63-
6447
pub fn projection_ty(
6548
self,
6649
tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -110,18 +93,35 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
11093
}
11194
}
11295

96+
impl From<Ty<'tcx>> for PlaceTy<'tcx> {
97+
fn from(ty: Ty<'tcx>) -> Self {
98+
PlaceTy::Ty { ty }
99+
}
100+
}
101+
113102
EnumTypeFoldableImpl! {
114103
impl<'tcx> TypeFoldable<'tcx> for PlaceTy<'tcx> {
115104
(PlaceTy::Ty) { ty },
116105
(PlaceTy::Downcast) { adt_def, substs, variant_index },
117106
}
118107
}
119108

109+
impl<'tcx> PlaceBase<'tcx> {
110+
pub fn ty(&self, local_decls: &impl HasLocalDecls<'tcx>) -> Ty<'tcx> {
111+
match self {
112+
PlaceBase::Local(index) => local_decls.local_decls()[*index].ty,
113+
PlaceBase::Promoted(data) => data.1,
114+
PlaceBase::Static(data) => data.ty,
115+
}
116+
}
117+
}
118+
120119
impl<'tcx> Place<'tcx> {
121-
pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> PlaceTy<'tcx>
122-
where
123-
D: HasLocalDecls<'tcx>,
124-
{
120+
pub fn ty<'a, 'gcx>(
121+
&self,
122+
local_decls: &impl HasLocalDecls<'tcx>,
123+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
124+
) -> PlaceTy<'tcx> {
125125
// the PlaceTy is the *final* type with all projection applied
126126
// if there is no projection, that just refers to `base`:
127127
//
@@ -133,7 +133,7 @@ impl<'tcx> Place<'tcx> {
133133
// ^^-- no projection
134134
// ^^^^-- PlaceTy
135135

136-
let mut place_ty = PlaceTy::base_ty(local_decls, &self.base);
136+
let mut place_ty = PlaceTy::from(self.base.ty(local_decls));
137137

138138
// apply .projection_ty() to all elems but only returns the final one.
139139
if !self.elems.is_empty() {

0 commit comments

Comments
 (0)