@@ -33,10 +33,6 @@ pub enum PlaceTy<'tcx> {
33
33
}
34
34
35
35
impl < ' a , ' gcx , ' tcx > PlaceTy < ' tcx > {
36
- pub fn from_ty ( ty : Ty < ' tcx > ) -> PlaceTy < ' tcx > {
37
- PlaceTy :: Ty { ty }
38
- }
39
-
40
36
pub fn to_ty ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Ty < ' tcx > {
41
37
match * self {
42
38
PlaceTy :: Ty { ty } => ty,
@@ -48,19 +44,6 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
48
44
}
49
45
}
50
46
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
-
64
47
pub fn projection_ty (
65
48
self ,
66
49
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
@@ -110,18 +93,35 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
110
93
}
111
94
}
112
95
96
+ impl From < Ty < ' tcx > > for PlaceTy < ' tcx > {
97
+ fn from ( ty : Ty < ' tcx > ) -> Self {
98
+ PlaceTy :: Ty { ty }
99
+ }
100
+ }
101
+
113
102
EnumTypeFoldableImpl ! {
114
103
impl <' tcx> TypeFoldable <' tcx> for PlaceTy <' tcx> {
115
104
( PlaceTy :: Ty ) { ty } ,
116
105
( PlaceTy :: Downcast ) { adt_def, substs, variant_index } ,
117
106
}
118
107
}
119
108
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
+
120
119
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 > {
125
125
// the PlaceTy is the *final* type with all projection applied
126
126
// if there is no projection, that just refers to `base`:
127
127
//
@@ -133,7 +133,7 @@ impl<'tcx> Place<'tcx> {
133
133
// ^^-- no projection
134
134
// ^^^^-- PlaceTy
135
135
136
- let mut place_ty = PlaceTy :: base_ty ( local_decls , & self . base ) ;
136
+ let mut place_ty = PlaceTy :: from ( self . base . ty ( local_decls ) ) ;
137
137
138
138
// apply .projection_ty() to all elems but only returns the final one.
139
139
if !self . elems . is_empty ( ) {
0 commit comments