@@ -237,88 +237,88 @@ impl<'tcx> Cx<'tcx> {
237237 ///
238238 /// Dealing with user type annotations is left to the caller.
239239 fn mirror_expr_cast (
240- & mut self ,
241- source : & ' tcx hir:: Expr < ' tcx > ,
242- temp_lifetime : TempLifetime ,
243- span : Span ,
244- ) -> ExprKind < ' tcx > {
245- let tcx = self . tcx ;
246-
247- // Check to see if this cast is a "coercion cast", where the cast is actually done
248- // using a coercion (or is a no-op).
249- if self . typeck_results ( ) . is_coercion_cast ( source. hir_id ) {
250- // Convert the lexpr to a vexpr.
251- ExprKind :: Use { source : self . mirror_expr ( source) }
252- } else if self . typeck_results ( ) . expr_ty ( source) . is_ref ( ) {
253- // Special cased so that we can type check that the element
254- // type of the source matches the pointed to type of the
255- // destination.
256- ExprKind :: PointerCoercion {
257- source : self . mirror_expr ( source) ,
258- cast : PointerCoercion :: ArrayToPointer ,
259- is_from_as_cast : true ,
260- }
261- } else if let hir:: ExprKind :: Path ( ref qpath) = source. kind
262- && let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id )
263- && let ty = self . typeck_results ( ) . node_type ( source. hir_id )
264- && let ty:: Adt ( adt_def, args) = ty. kind ( )
265- && let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
266- {
267- // Check whether this is casting an enum variant discriminant.
268- // To prevent cycles, we refer to the discriminant initializer,
269- // which is always an integer and thus doesn't need to know the
270- // enum's layout (or its tag type) to compute it during const eval.
271- // Example:
272- // enum Foo {
273- // A,
274- // B = A as isize + 4,
275- // }
276- // The correct solution would be to add symbolic computations to miri,
277- // so we wouldn't have to compute and store the actual value
278-
279- let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
280- let ( discr_did, discr_offset) = adt_def. discriminant_def_for_variant ( idx) ;
281-
282- use rustc_middle:: ty:: util:: IntTypeExt ;
283- let ty = adt_def. repr ( ) . discr_type ( ) ;
284- let discr_ty = ty. to_ty ( tcx) ;
285-
286- let size = tcx
287- . layout_of ( self . typing_env ( ) . as_query_input ( discr_ty) )
288- . unwrap_or_else ( |e| panic ! ( "could not compute layout for {discr_ty:?}: {e:?}" ) )
289- . size ;
290-
291- let ( lit, overflowing) = ScalarInt :: truncate_from_uint ( discr_offset as u128 , size) ;
292- if overflowing {
293- // An erroneous enum with too many variants for its repr will emit E0081 and E0370
294- self . tcx . dcx ( ) . span_delayed_bug (
295- source. span ,
296- "overflowing enum wasn't rejected by hir analysis" ,
297- ) ;
240+ & mut self ,
241+ source : & ' tcx hir:: Expr < ' tcx > ,
242+ temp_lifetime : TempLifetime ,
243+ span : Span ,
244+ ) -> ExprKind < ' tcx > {
245+ let tcx = self . tcx ;
246+
247+ // Check to see if this cast is a "coercion cast", where the cast is actually done
248+ // using a coercion (or is a no-op).
249+ if self . typeck_results ( ) . is_coercion_cast ( source. hir_id ) {
250+ // Convert the lexpr to a vexpr.
251+ ExprKind :: Use { source : self . mirror_expr ( source) }
252+ } else if self . typeck_results ( ) . expr_ty ( source) . is_ref ( ) {
253+ // Special cased so that we can type check that the element
254+ // type of the source matches the pointed to type of the
255+ // destination.
256+ ExprKind :: PointerCoercion {
257+ source : self . mirror_expr ( source) ,
258+ cast : PointerCoercion :: ArrayToPointer ,
259+ is_from_as_cast : true ,
260+ }
261+ } else if let hir:: ExprKind :: Path ( ref qpath) = source. kind
262+ && let res = self . typeck_results ( ) . qpath_res ( qpath, source. hir_id )
263+ && let ty = self . typeck_results ( ) . node_type ( source. hir_id )
264+ && let ty:: Adt ( adt_def, args) = ty. kind ( )
265+ && let Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , variant_ctor_id) = res
266+ {
267+ // Check whether this is casting an enum variant discriminant.
268+ // To prevent cycles, we refer to the discriminant initializer,
269+ // which is always an integer and thus doesn't need to know the
270+ // enum's layout (or its tag type) to compute it during const eval.
271+ // Example:
272+ // enum Foo {
273+ // A,
274+ // B = A as isize + 4,
275+ // }
276+ // The correct solution would be to add symbolic computations to miri,
277+ // so we wouldn't have to compute and store the actual value
278+
279+ let idx = adt_def. variant_index_with_ctor_id ( variant_ctor_id) ;
280+ let ( discr_did, discr_offset) = adt_def. discriminant_def_for_variant ( idx) ;
281+
282+ use rustc_middle:: ty:: util:: IntTypeExt ;
283+ let ty = adt_def. repr ( ) . discr_type ( ) ;
284+ let discr_ty = ty. to_ty ( tcx) ;
285+
286+ let size = tcx
287+ . layout_of ( self . typing_env . as_query_input ( discr_ty) )
288+ . unwrap_or_else ( |e| panic ! ( "could not compute layout for {discr_ty:?}: {e:?}" ) )
289+ . size ;
290+
291+ let ( lit, overflowing) = ScalarInt :: truncate_from_uint ( discr_offset as u128 , size) ;
292+ if overflowing {
293+ // An erroneous enum with too many variants for its repr will emit E0081 and E0370
294+ self . tcx . dcx ( ) . span_delayed_bug (
295+ source. span ,
296+ "overflowing enum wasn't rejected by hir analysis" ,
297+ ) ;
298+ }
299+ let kind = ExprKind :: NonHirLiteral { lit, user_ty : None } ;
300+ let offset = self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
301+
302+ let source = match discr_did {
303+ // in case we are offsetting from a computed discriminant
304+ // and not the beginning of discriminants (which is always `0`)
305+ Some ( did) => {
306+ let kind = ExprKind :: NamedConst { def_id : did, args, user_ty : None } ;
307+ let lhs =
308+ self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
309+ let bin = ExprKind :: Binary { op : BinOp :: Add , lhs, rhs : offset } ;
310+ self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind : bin } )
298311 }
299- let kind = ExprKind :: NonHirLiteral { lit, user_ty : None } ;
300- let offset = self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
301-
302- let source = match discr_did {
303- // in case we are offsetting from a computed discriminant
304- // and not the beginning of discriminants (which is always `0`)
305- Some ( did) => {
306- let kind = ExprKind :: NamedConst { def_id : did, args, user_ty : None } ;
307- let lhs =
308- self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind } ) ;
309- let bin = ExprKind :: Binary { op : BinOp :: Add , lhs, rhs : offset } ;
310- self . thir . exprs . push ( Expr { temp_lifetime, ty : discr_ty, span, kind : bin } )
311- }
312- None => offset,
313- } ;
312+ None => offset,
313+ } ;
314314
315- ExprKind :: Cast { source }
316- } else {
317- // Default to `ExprKind::Cast` for all explicit casts.
318- // MIR building then picks the right MIR casts based on the types.
319- ExprKind :: Cast { source : self . mirror_expr ( source) }
320- }
315+ ExprKind :: Cast { source }
316+ } else {
317+ // Default to `ExprKind::Cast` for all explicit casts.
318+ // MIR building then picks the right MIR casts based on the types.
319+ ExprKind :: Cast { source : self . mirror_expr ( source) }
321320 }
321+ }
322322
323323 #[ instrument( level = "debug" , skip( self ) , ret) ]
324324 fn make_mirror_unadjusted ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) -> Expr < ' tcx > {
@@ -1040,7 +1040,7 @@ impl<'tcx> Cx<'tcx> {
10401040 // but distinguish between &STATIC and &THREAD_LOCAL as they have different semantics
10411041 Res :: Def ( DefKind :: Static { .. } , id) => {
10421042 // this is &raw for extern static or static mut, and & for other statics
1043- let ty = self . tcx . static_ptr_ty ( id, self . typing_env ( ) ) ;
1043+ let ty = self . tcx . static_ptr_ty ( id, self . typing_env ) ;
10441044 let ( temp_lifetime, backwards_incompatible) = self
10451045 . rvalue_scopes
10461046 . temporary_scope ( self . region_scope_tree , expr. hir_id . local_id ) ;
@@ -1240,14 +1240,14 @@ impl<'tcx> Cx<'tcx> {
12401240
12411241 /// Converts a list of named fields (i.e., for struct-like struct/enum ADTs) into FieldExpr.
12421242 fn field_refs ( & mut self , fields : & ' tcx [ hir:: ExprField < ' tcx > ] ) -> Box < [ FieldExpr ] > {
1243- fields
1244- . iter ( )
1245- . map ( |field| FieldExpr {
1246- name : self . typeck_results . field_index ( field. hir_id ) ,
1247- expr : self . mirror_expr ( field. expr ) ,
1248- } )
1249- . collect ( )
1250- }
1243+ fields
1244+ . iter ( )
1245+ . map ( |field| FieldExpr {
1246+ name : self . typeck_results . field_index ( field. hir_id ) ,
1247+ expr : self . mirror_expr ( field. expr ) ,
1248+ } )
1249+ . collect ( )
1250+ }
12511251}
12521252
12531253trait ToBorrowKind {
0 commit comments