@@ -83,7 +83,7 @@ impl<'a, 'gcx, 'tcx> LvalueTy<'tcx> {
8383 variant_index : index }
8484 }
8585 _ => {
86- bug ! ( "cannot downcast non-enum type: `{:?}` as `{:?}` " , self , elem )
86+ bug ! ( "cannot downcast non-enum type: `{:?}`" , self )
8787 }
8888 } ,
8989 ProjectionElem :: Field ( _, fty) => LvalueTy :: Ty { ty : fty }
@@ -113,26 +113,16 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
113113 }
114114}
115115
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) =>
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) =>
136126 LvalueTy :: Ty { ty : tcx. lookup_item_type ( def_id) . ty } ,
137127 & Lvalue :: ReturnPointer =>
138128 LvalueTy :: Ty { ty : mir. return_ty } ,
@@ -163,17 +153,17 @@ impl<'tcx> Rvalue<'tcx> {
163153 }
164154 ) )
165155 }
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) )
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) )
172162 }
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) ;
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) ;
177167 let ty = tcx. mk_tup ( vec ! [ ty, tcx. types. bool ] ) ;
178168 Some ( ty)
179169 }
0 commit comments