@@ -368,7 +368,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
368368 // Some intrinsics are handled here because they desperately want to avoid introducing
369369 // unnecessary copies.
370370 ExprKind :: Call { ty, fun, ref args, .. }
371- if let ty:: FnDef ( def_id, generic_args ) = ty. kind ( )
371+ if let ty:: FnDef ( def_id, _generic_args ) = ty. kind ( )
372372 && let Some ( intrinsic) = this. tcx . intrinsic ( def_id)
373373 && matches ! ( intrinsic. name, sym:: write_via_move | sym:: init_box_via_move) =>
374374 {
@@ -396,15 +396,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
396396 this. expr_into_dest ( ptr_deref, block, val)
397397 }
398398 sym:: init_box_via_move => {
399- // `write_via_move (b, val)` becomes
399+ // `init_box_via_move (b, val)` becomes
400400 // ```
401- // *transmute::<_, *mut T>(b) = val;
401+ // *transmute::<_, *mut T>(b.0 ) = val;
402402 // transmute::<_, Box<T>>(b)
403403 // ```
404- let t = generic_args. type_at ( 0 ) ;
405404 let [ b, val] = * * args else {
406405 span_bug ! ( expr_span, "invalid init_box_via_move call" )
407406 } ;
407+ // We get the type from `val` to (hopefully) ensure the lifetimes match.
408+ // FIXME: That does not work.
409+ let t = this. thir . exprs [ val] . ty ;
410+
408411 let Some ( b) = unpack ! ( block = this. as_local_operand( block, b) ) . place ( )
409412 else {
410413 span_bug ! ( expr_span, "invalid init_box_via_move call" )
@@ -435,7 +438,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
435438 & [ ProjectionElem :: Field ( rustc_abi:: FieldIdx :: ZERO , unique_ty) ] ,
436439 this. tcx ,
437440 ) ;
438- // `ptr` is `b` transmuted to `*mut T`.
441+ // `ptr` is `b.0 ` transmuted to `*mut T`.
439442 let ptr_ty = Ty :: new_mut_ptr ( this. tcx , t) ;
440443 let ptr = this. local_decls . push ( LocalDecl :: new ( ptr_ty, expr_span) ) ;
441444 this. cfg . push (
0 commit comments