tail expression behind terminating scope

This commit is contained in:
Ding Xiang Fei 2024-04-12 23:24:45 +08:00
parent 11380368dc
commit 0f8c3f7882
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
19 changed files with 377 additions and 24 deletions

View file

@ -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;