@@ -221,6 +221,12 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
221221 Project ,
222222 Local ,
223223 }
224+ // Here we are looking for a chain of access to extract a place reference for
225+ // a local variable.
226+ // For instance, given `&*(&*x[y]).z().u`, `probe` will pick out
227+ // the sub-expressions `&*x[y]` and `y` as expressions making accesses to locals.
228+ // The place references generated can be discarded earlier as MIR allows,
229+ // and, thus, can be assigned a smaller region.
224230 loop {
225231 match nested_expr. kind {
226232 hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
@@ -268,6 +274,9 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
268274 }
269275 }
270276 OpTy :: Project => {
277+ // The generated MIR produces temporaries for the each of the nested references,
278+ // such as `&x`, `&&x` in `(&&&x).y` for the field access of `y`.
279+ // These temporaries must stay alive even after the field access.
271280 ref_level. clear ( ) ;
272281 }
273282 OpTy :: Local => {
@@ -290,6 +299,8 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
290299 | hir:: ExprKind :: Field ( ..)
291300 | hir:: ExprKind :: Index ( ..)
292301 | hir:: ExprKind :: Path ( ..) => self . probe ( expr) ,
302+
303+ // We do not probe into other function bodies or blocks.
293304 hir:: ExprKind :: Block ( ..)
294305 | hir:: ExprKind :: Closure ( ..)
295306 | hir:: ExprKind :: ConstBlock ( ..) => { }
@@ -300,7 +311,6 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
300311 let mut locals = Default :: default ( ) ;
301312 let mut resolution_visitor = LocalAccessResolutionVisitor { locals : & mut locals } ;
302313 resolution_visitor. visit_expr ( expr) ;
303- // visitor.terminating_scopes.extend(locals.iter().copied());
304314 locals
305315}
306316
0 commit comments