@@ -113,16 +113,26 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
113
113
}
114
114
}
115
115
116
- impl < ' tcx > Lvalue < ' tcx > {
117
- pub fn ty < ' a , ' gcx > ( & self , mir : & Mir < ' tcx > , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> LvalueTy < ' tcx > {
118
- match self {
119
- & Lvalue :: Var ( index) =>
120
- LvalueTy :: Ty { ty : mir. var_decls [ index] . ty } ,
121
- & Lvalue :: Temp ( index) =>
122
- LvalueTy :: Ty { ty : mir. temp_decls [ index] . ty } ,
123
- & Lvalue :: Arg ( index) =>
124
- LvalueTy :: Ty { ty : mir. arg_decls [ index] . ty } ,
125
- & Lvalue :: Static ( def_id) =>
116
+ impl < ' a , ' gcx , ' tcx > Mir < ' tcx > {
117
+ pub fn operand_ty ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
118
+ operand : & Operand < ' tcx > )
119
+ -> Ty < ' tcx >
120
+ {
121
+ match * operand {
122
+ Operand :: Consume ( ref l) => self . lvalue_ty ( tcx, l) . to_ty ( tcx) ,
123
+ Operand :: Constant ( ref c) => c. ty ,
124
+ }
125
+ }
126
+
127
+ pub fn ty ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > , lvalue : & Lvalue < ' tcx > ) -> LvalueTy < ' tcx > {
128
+ match * lvalue {
129
+ Lvalue :: Var ( index) =>
130
+ LvalueTy :: Ty { ty : self . var_decls [ index] . ty } ,
131
+ Lvalue :: Temp ( index) =>
132
+ LvalueTy :: Ty { ty : self . temp_decls [ index] . ty } ,
133
+ Lvalue :: Arg ( index) =>
134
+ LvalueTy :: Ty { ty : self . arg_decls [ index] . ty } ,
135
+ Lvalue :: Static ( def_id) =>
126
136
LvalueTy :: Ty { ty : tcx. lookup_item_type ( def_id) . ty } ,
127
137
& Lvalue :: ReturnPointer =>
128
138
LvalueTy :: Ty { ty : mir. return_ty } ,
@@ -153,17 +163,17 @@ impl<'tcx> Rvalue<'tcx> {
153
163
}
154
164
) )
155
165
}
156
- & Rvalue :: Len ( ..) => Some ( tcx. types . usize ) ,
157
- & Rvalue :: Cast ( _, _, ty) => Some ( ty) ,
158
- & Rvalue :: BinaryOp ( op, ref lhs, ref rhs) => {
159
- let lhs_ty = lhs . ty ( mir , tcx ) ;
160
- let rhs_ty = rhs . ty ( mir , tcx ) ;
161
- Some ( op . ty ( tcx, lhs_ty, rhs_ty) )
166
+ Rvalue :: Len ( ..) => Some ( tcx. types . usize ) ,
167
+ Rvalue :: Cast ( _, _, ty) => Some ( ty) ,
168
+ Rvalue :: BinaryOp ( op, ref lhs, ref rhs) => {
169
+ let lhs_ty = self . operand_ty ( tcx , lhs ) ;
170
+ let rhs_ty = self . operand_ty ( tcx , rhs ) ;
171
+ Some ( binop_ty ( tcx, op , lhs_ty, rhs_ty) )
162
172
}
163
- & Rvalue :: CheckedBinaryOp ( op, ref lhs, ref rhs) => {
164
- let lhs_ty = lhs . ty ( mir , tcx ) ;
165
- let rhs_ty = rhs . ty ( mir , tcx ) ;
166
- let ty = op . ty ( tcx, lhs_ty, rhs_ty) ;
173
+ Rvalue :: CheckedBinaryOp ( op, ref lhs, ref rhs) => {
174
+ let lhs_ty = self . operand_ty ( tcx , lhs ) ;
175
+ let rhs_ty = self . operand_ty ( tcx , rhs ) ;
176
+ let ty = binop_ty ( tcx, op , lhs_ty, rhs_ty) ;
167
177
let ty = tcx. mk_tup ( vec ! [ ty, tcx. types. bool ] ) ;
168
178
Some ( ty)
169
179
}
@@ -247,26 +257,3 @@ impl BorrowKind {
247
257
}
248
258
}
249
259
}
250
-
251
- impl BinOp {
252
- pub fn to_hir_binop ( self ) -> hir:: BinOp_ {
253
- match self {
254
- BinOp :: Add => hir:: BinOp_ :: BiAdd ,
255
- BinOp :: Sub => hir:: BinOp_ :: BiSub ,
256
- BinOp :: Mul => hir:: BinOp_ :: BiMul ,
257
- BinOp :: Div => hir:: BinOp_ :: BiDiv ,
258
- BinOp :: Rem => hir:: BinOp_ :: BiRem ,
259
- BinOp :: BitXor => hir:: BinOp_ :: BiBitXor ,
260
- BinOp :: BitAnd => hir:: BinOp_ :: BiBitAnd ,
261
- BinOp :: BitOr => hir:: BinOp_ :: BiBitOr ,
262
- BinOp :: Shl => hir:: BinOp_ :: BiShl ,
263
- BinOp :: Shr => hir:: BinOp_ :: BiShr ,
264
- BinOp :: Eq => hir:: BinOp_ :: BiEq ,
265
- BinOp :: Ne => hir:: BinOp_ :: BiNe ,
266
- BinOp :: Lt => hir:: BinOp_ :: BiLt ,
267
- BinOp :: Gt => hir:: BinOp_ :: BiGt ,
268
- BinOp :: Le => hir:: BinOp_ :: BiLe ,
269
- BinOp :: Ge => hir:: BinOp_ :: BiGe
270
- }
271
- }
272
- }
0 commit comments