Rollup merge of #125293 - dingxiangfei2009:tail-expr-temp-lifetime, r=estebank,davidtwco
Place tail expression behind terminating scope This PR implements #123739 so that we can do further experiments in nightly. A little rewrite has been applied to `for await` lowering. It was previously `unsafe { Pin::unchecked_new(into_async_iter(..)) }`. Under the edition 2024 rule, however, `into_async_iter` gets dropped at the end of the `unsafe` block. This presumably the first Edition 2024 migration rule goes by hoisting `into_async_iter(..)` into `match` one level above, so it now looks like the following. ```rust match into_async_iter($iter_expr) { ref mut iter => match unsafe { Pin::unchecked_new(iter) } { ... } } ```
This commit is contained in:
commit
8eb2e5f4c8
19 changed files with 377 additions and 24 deletions
|
@ -6,7 +6,6 @@
|
|||
//!
|
||||
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
|
||||
|
||||
use rustc_ast::visit::visit_opt;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -168,7 +167,14 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
|
|||
hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => visitor.visit_stmt(statement),
|
||||
}
|
||||
}
|
||||
visit_opt!(visitor, visit_expr, &blk.expr);
|
||||
if let Some(tail_expr) = blk.expr {
|
||||
if visitor.tcx.features().shorter_tail_lifetimes
|
||||
&& blk.span.edition().at_least_rust_2024()
|
||||
{
|
||||
visitor.terminating_scopes.insert(tail_expr.hir_id.local_id);
|
||||
}
|
||||
visitor.visit_expr(tail_expr);
|
||||
}
|
||||
}
|
||||
|
||||
visitor.cx = prev_cx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue