File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
compiler/rustc_hir_analysis/src/check Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -467,6 +467,7 @@ fn resolve_local<'tcx>(
467467 // A, but the inner rvalues `a()` and `b()` have an extended lifetime
468468 // due to rule C.
469469
470+ let mut extend_initializer = true ;
470471 if let_kind == LetKind :: Super {
471472 if let Some ( scope) = visitor. extended_super_lets . remove ( & pat. unwrap ( ) . hir_id . local_id ) {
472473 // This expression was lifetime-extended by a parent let binding. E.g.
@@ -497,10 +498,17 @@ fn resolve_local<'tcx>(
497498 }
498499 visitor. cx . var_parent = parent;
499500 }
501+ // Don't lifetime-extend child `super let`s or block tail expressions' temporaries in
502+ // the initialzer when this `super let` is not itself extended by a parent `let`
503+ // (#145784). Block tail expressions are temporary drop scopes in Editions 2024 and
504+ // later, their temps shouldn't outlive the block in e.g. `f(pin!({ &temp() }))`.
505+ extend_initializer = false ;
500506 }
501507 }
502508
503- if let Some ( expr) = init {
509+ if let Some ( expr) = init
510+ && extend_initializer
511+ {
504512 record_rvalue_scope_if_borrow_expr ( visitor, expr, visitor. cx . var_parent ) ;
505513
506514 if let Some ( pat) = pat {
Original file line number Diff line number Diff line change @@ -46,10 +46,10 @@ fn main() {
4646 #[ cfg( e2024) ]
4747 (
4848 pin ! ( (
49- pin!( { & o. log( 3 ) as * const LogDrop <' _> } ) ,
50- drop( o. log( 1 ) ) ,
49+ pin!( { & o. log( 1 ) as * const LogDrop <' _> } ) ,
50+ drop( o. log( 2 ) ) ,
5151 ) ) ,
52- drop ( o. log ( 2 ) ) ,
52+ drop ( o. log ( 3 ) ) ,
5353 ) ;
5454 } ) ;
5555
@@ -70,12 +70,12 @@ fn main() {
7070 (
7171 {
7272 super let _ = {
73- super let _ = { & o. log ( 4 ) as * const LogDrop < ' _ > } ;
74- drop ( o. log ( 1 ) )
73+ super let _ = { & o. log ( 1 ) as * const LogDrop < ' _ > } ;
74+ drop ( o. log ( 2 ) )
7575 } ;
76- drop ( o. log ( 2 ) )
76+ drop ( o. log ( 3 ) )
7777 } ,
78- drop ( o. log ( 3 ) ) ,
78+ drop ( o. log ( 4 ) ) ,
7979 ) ;
8080 } ) ;
8181
You can’t perform that action at this time.
0 commit comments