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 initializer 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 @@ -45,10 +45,10 @@ fn main() {
4545 #[ cfg( e2024) ]
4646 (
4747 pin ! ( (
48- pin!( { & o. log( 3 ) as * const LogDrop <' _> } ) ,
49- drop( o. log( 1 ) ) ,
48+ pin!( { & o. log( 1 ) as * const LogDrop <' _> } ) ,
49+ drop( o. log( 2 ) ) ,
5050 ) ) ,
51- drop ( o. log ( 2 ) ) ,
51+ drop ( o. log ( 3 ) ) ,
5252 ) ;
5353 } ) ;
5454
@@ -69,12 +69,12 @@ fn main() {
6969 (
7070 {
7171 super let _ = {
72- super let _ = { & o. log ( 4 ) as * const LogDrop < ' _ > } ;
73- drop ( o. log ( 1 ) )
72+ super let _ = { & o. log ( 1 ) as * const LogDrop < ' _ > } ;
73+ drop ( o. log ( 2 ) )
7474 } ;
75- drop ( o. log ( 2 ) )
75+ drop ( o. log ( 3 ) )
7676 } ,
77- drop ( o. log ( 3 ) ) ,
77+ drop ( o. log ( 4 ) ) ,
7878 ) ;
7979 } ) ;
8080
You can’t perform that action at this time.
0 commit comments