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>(
467
467
// A, but the inner rvalues `a()` and `b()` have an extended lifetime
468
468
// due to rule C.
469
469
470
+ let mut extend_initializer = true ;
470
471
if let_kind == LetKind :: Super {
471
472
if let Some ( scope) = visitor. extended_super_lets . remove ( & pat. unwrap ( ) . hir_id . local_id ) {
472
473
// This expression was lifetime-extended by a parent let binding. E.g.
@@ -497,10 +498,17 @@ fn resolve_local<'tcx>(
497
498
}
498
499
visitor. cx . var_parent = parent;
499
500
}
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 ;
500
506
}
501
507
}
502
508
503
- if let Some ( expr) = init {
509
+ if let Some ( expr) = init
510
+ && extend_initializer
511
+ {
504
512
record_rvalue_scope_if_borrow_expr ( visitor, expr, visitor. cx . var_parent ) ;
505
513
506
514
if let Some ( pat) = pat {
Original file line number Diff line number Diff line change @@ -46,10 +46,10 @@ fn main() {
46
46
#[ cfg( e2024) ]
47
47
(
48
48
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 ) ) ,
51
51
) ) ,
52
- drop ( o. log ( 2 ) ) ,
52
+ drop ( o. log ( 3 ) ) ,
53
53
) ;
54
54
} ) ;
55
55
@@ -70,12 +70,12 @@ fn main() {
70
70
(
71
71
{
72
72
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 ) )
75
75
} ;
76
- drop ( o. log ( 2 ) )
76
+ drop ( o. log ( 3 ) )
77
77
} ,
78
- drop ( o. log ( 3 ) ) ,
78
+ drop ( o. log ( 4 ) ) ,
79
79
) ;
80
80
} ) ;
81
81
You can’t perform that action at this time.
0 commit comments