@@ -159,6 +159,9 @@ impl<'tcx> Cx<'tcx> {
159159 Expr { temp_lifetime, ty : adjustment. target , span, kind }
160160 }
161161
162+ /// Lowers a cast expression.
163+ ///
164+ /// Dealing with user type annotations is left to the caller.
162165 fn mirror_expr_cast (
163166 & mut self ,
164167 source : & ' tcx hir:: Expr < ' tcx > ,
@@ -198,25 +201,23 @@ impl<'tcx> Cx<'tcx> {
198201 } ;
199202
200203 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 {
204206 return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
205207 } ;
206- let Res :: Def (
208+ let Res :: Def (
207209 DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) ,
208210 variant_ctor_id,
209211 ) = res else {
210212 return ExprKind :: Cast { source : self . mirror_expr ( source) } ;
211213 } ;
212214
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) ;
220221
221222 let param_env_ty = self . param_env . and ( discr_ty) ;
222223 let size = tcx
@@ -231,10 +232,9 @@ impl<'tcx> Cx<'tcx> {
231232 let offset = self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
232233
233234 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`)
234237 Some ( did) => {
235- // in case we are offsetting from a computed discriminant
236- // and not the beginning of discriminants (which is always `0`)
237-
238238 let kind = ExprKind :: NamedConst { def_id : did, substs, user_ty : None } ;
239239 let lhs =
240240 self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
0 commit comments