@@ -159,6 +159,9 @@ impl<'tcx> Cx<'tcx> {
159
159
Expr { temp_lifetime, ty : adjustment. target , span, kind }
160
160
}
161
161
162
+ /// Lowers a cast expression.
163
+ ///
164
+ /// Dealing with user type annotations is left to the caller.
162
165
fn mirror_expr_cast (
163
166
& mut self ,
164
167
source : & ' tcx hir:: Expr < ' tcx > ,
@@ -198,25 +201,23 @@ impl<'tcx> Cx<'tcx> {
198
201
} ;
199
202
200
203
let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id ) ;
201
- let ( discr_did, discr_offset, discr_ty, substs) = {
202
- let ty = self . typeck_results ( ) . node_type ( source. hir_id ) ;
203
- let ty:: Adt ( adt_def, substs) = ty. kind ( ) else {
204
+ let ty = self . typeck_results ( ) . node_type ( source. hir_id ) ;
205
+ let ty:: Adt ( adt_def, substs) = ty. kind ( ) else {
204
206
return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
205
207
} ;
206
- let Res :: Def (
208
+ let Res :: Def (
207
209
DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) ,
208
210
variant_ctor_id,
209
211
) = res else {
210
212
return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
211
213
} ;
212
214
213
- let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
214
- let ( d, o) = adt_def. discriminant_def_for_variant ( idx) ;
215
- use rustc_middle:: ty:: util:: IntTypeExt ;
216
- let ty = adt_def. repr ( ) . discr_type ( ) ;
217
- let ty = ty. to_ty ( tcx) ;
218
- ( d, o, ty, substs)
219
- } ;
215
+ let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
216
+ let ( discr_did, discr_offset) = adt_def. discriminant_def_for_variant ( idx) ;
217
+
218
+ use rustc_middle:: ty:: util:: IntTypeExt ;
219
+ let ty = adt_def. repr ( ) . discr_type ( ) ;
220
+ let discr_ty = ty. to_ty ( tcx) ;
220
221
221
222
let param_env_ty = self . param_env . and ( discr_ty) ;
222
223
let size = tcx
@@ -231,10 +232,9 @@ impl<'tcx> Cx<'tcx> {
231
232
let offset = self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
232
233
233
234
let source = match discr_did {
235
+ // in case we are offsetting from a computed discriminant
236
+ // and not the beginning of discriminants (which is always `0`)
234
237
Some ( did) => {
235
- // in case we are offsetting from a computed discriminant
236
- // and not the beginning of discriminants (which is always `0`)
237
-
238
238
let kind = ExprKind :: NamedConst { def_id : did, substs, user_ty : None } ;
239
239
let lhs =
240
240
self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
0 commit comments