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 @@ -45,10 +45,10 @@ fn main() {
45
45
#[ cfg( e2024) ]
46
46
(
47
47
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 ) ) ,
50
50
) ) ,
51
- drop ( o. log ( 2 ) ) ,
51
+ drop ( o. log ( 3 ) ) ,
52
52
) ;
53
53
} ) ;
54
54
@@ -69,12 +69,12 @@ fn main() {
69
69
(
70
70
{
71
71
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 ) )
74
74
} ;
75
- drop ( o. log ( 2 ) )
75
+ drop ( o. log ( 3 ) )
76
76
} ,
77
- drop ( o. log ( 3 ) ) ,
77
+ drop ( o. log ( 4 ) ) ,
78
78
) ;
79
79
} ) ;
80
80
You can’t perform that action at this time.
0 commit comments