@@ -503,10 +503,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
503503 block. and ( place_builder)
504504 }
505505 ExprKind :: ValueTypeAscription { source, ref user_ty, user_ty_span } => {
506- let source_expr = & this. thir [ source] ;
507- let temp = unpack ! (
508- block = this. as_temp( block, source_expr. temp_lifetime, source, mutability)
509- ) ;
506+ let temp_lifetime =
507+ this. region_scope_tree . temporary_scope ( this. thir [ source] . temp_scope_id ) ;
508+ let temp = unpack ! ( block = this. as_temp( block, temp_lifetime, source, mutability) ) ;
510509 if let Some ( user_ty) = user_ty {
511510 let ty_source_info = this. source_info ( user_ty_span) ;
512511 let annotation_index =
@@ -539,10 +538,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
539538 block. and ( place_builder. project ( PlaceElem :: UnwrapUnsafeBinder ( expr. ty ) ) )
540539 }
541540 ExprKind :: ValueUnwrapUnsafeBinder { source } => {
542- let source_expr = & this. thir [ source] ;
543- let temp = unpack ! (
544- block = this. as_temp( block, source_expr. temp_lifetime, source, mutability)
545- ) ;
541+ let temp_lifetime =
542+ this. region_scope_tree . temporary_scope ( this. thir [ source] . temp_scope_id ) ;
543+ let temp = unpack ! ( block = this. as_temp( block, temp_lifetime, source, mutability) ) ;
546544 block. and ( PlaceBuilder :: from ( temp) . project ( PlaceElem :: UnwrapUnsafeBinder ( expr. ty ) ) )
547545 }
548546
@@ -590,8 +588,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
590588 | ExprKind :: WrapUnsafeBinder { .. } => {
591589 // these are not places, so we need to make a temporary.
592590 debug_assert ! ( !matches!( Category :: of( & expr. kind) , Some ( Category :: Place ) ) ) ;
593- let temp =
594- unpack ! ( block = this. as_temp( block, expr . temp_lifetime, expr_id, mutability) ) ;
591+ let temp_lifetime = this . region_scope_tree . temporary_scope ( expr . temp_scope_id ) ;
592+ let temp = unpack ! ( block = this. as_temp( block, temp_lifetime, expr_id, mutability) ) ;
595593 block. and ( PlaceBuilder :: from ( temp) )
596594 }
597595 }
@@ -637,7 +635,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
637635 // Making this a *fresh* temporary means we do not have to worry about
638636 // the index changing later: Nothing will ever change this temporary.
639637 // The "retagging" transformation (for Stacked Borrows) relies on this.
640- let index_lifetime = self . thir [ index] . temp_lifetime ;
638+ // Using the enclosing temporary scope for the index ensures it will live past where this
639+ // place is used. This lifetime may be larger than strictly necessary but it means we don't
640+ // need to pass a scope for operands to `as_place`.
641+ let index_lifetime = self . region_scope_tree . temporary_scope ( self . thir [ index] . temp_scope_id ) ;
641642 let idx = unpack ! ( block = self . as_temp( block, index_lifetime, index, Mutability :: Not ) ) ;
642643
643644 block = self . bounds_check ( block, & base_place, idx, expr_span, source_info) ;
0 commit comments